@netless/telebox-insider 0.2.26 → 1.0.0-alpha.11
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.
- package/dist/TeleBox/constants.d.ts +0 -3
- package/dist/TeleBox/index.d.ts +121 -97
- package/dist/TeleBox/typings.d.ts +44 -55
- package/dist/TeleBoxCollector/index.d.ts +27 -29
- package/dist/TeleBoxManager/MaxTitleBar/index.d.ts +14 -18
- package/dist/TeleBoxManager/constants.d.ts +0 -3
- package/dist/TeleBoxManager/index.d.ts +64 -19
- package/dist/TeleBoxManager/typings.d.ts +35 -28
- package/dist/TeleStage/index.d.ts +21 -0
- package/dist/TeleTitleBar/DefaultTitleBar/index.d.ts +5 -9
- package/dist/TeleTitleBar/typings.d.ts +4 -6
- package/dist/index.d.ts +0 -1
- package/dist/style.css +1 -1
- package/dist/telebox-insider.cjs.js +1 -15
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +1 -15
- package/dist/telebox-insider.es.js.map +1 -1
- package/dist/utils.d.ts +0 -1
- package/package.json +7 -19
- package/src/TeleBox/constants.ts +0 -3
- package/src/TeleBox/index.ts +527 -689
- package/src/TeleBox/style.scss +1 -0
- package/src/TeleBox/typings.ts +44 -75
- package/src/TeleBoxCollector/index.ts +151 -159
- package/src/TeleBoxCollector/style.scss +1 -1
- package/src/TeleBoxManager/MaxTitleBar/index.ts +88 -108
- package/src/TeleBoxManager/MaxTitleBar/style.scss +5 -2
- package/src/TeleBoxManager/constants.ts +0 -3
- package/src/TeleBoxManager/index.ts +333 -336
- package/src/TeleBoxManager/typings.ts +45 -53
- package/src/TeleStage/index.ts +174 -0
- package/src/TeleStage/style.scss +49 -0
- package/src/TeleTitleBar/DefaultTitleBar/index.ts +44 -65
- package/src/TeleTitleBar/typings.ts +4 -10
- package/src/index.ts +0 -1
- package/src/scss/variables.scss +3 -0
- package/src/utils.ts +0 -6
- package/dist/TeleBoxCollector/TeleBoxCollector.stories.d.ts +0 -5
- package/dist/TeleBoxManager/MaxTitleBar/MaxTitleBar.stories.d.ts +0 -7
- package/dist/TeleBoxManager/MaxTitleBar/MaxTitleBarReact.d.ts +0 -4
- package/dist/TeleBoxReact/TeleBox.stories.d.ts +0 -9
- package/dist/TeleBoxReact/index.d.ts +0 -17
- package/dist/TeleBoxReact/utils.d.ts +0 -2
- package/dist/TeleTitleBar/DefaultTitleBar/DefaultTitleBar.stories.d.ts +0 -4
- package/src/TeleBoxCollector/TeleBoxCollector.stories.tsx +0 -23
- package/src/TeleBoxManager/MaxTitleBar/MaxTitleBar.stories.tsx +0 -66
- package/src/TeleBoxManager/MaxTitleBar/MaxTitleBarReact.tsx +0 -34
- package/src/TeleBoxReact/TeleBox.stories.tsx +0 -74
- package/src/TeleBoxReact/index.tsx +0 -175
- package/src/TeleBoxReact/utils.ts +0 -14
- package/src/TeleTitleBar/DefaultTitleBar/DefaultTitleBar.stories.tsx +0 -15
package/src/TeleBox/style.scss
CHANGED
package/src/TeleBox/typings.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type Emittery from "emittery";
|
|
2
|
+
import type { ReadonlyVal } from "value-enhancer";
|
|
2
3
|
import type { TeleTitleBar } from "../TeleTitleBar";
|
|
3
4
|
import type {
|
|
4
5
|
TeleBoxDragHandleType,
|
|
@@ -29,44 +30,34 @@ export interface TeleBoxConfig {
|
|
|
29
30
|
readonly id?: string;
|
|
30
31
|
/** Box title. Default empty. */
|
|
31
32
|
readonly title?: string;
|
|
32
|
-
/** Prefers Box color scheme. Default light. */
|
|
33
|
-
readonly prefersColorScheme?: TeleBoxColorScheme;
|
|
34
|
-
/** Actual Box Dark Mode */
|
|
35
|
-
readonly darkMode?: boolean;
|
|
36
33
|
/** Box visible. Default true. */
|
|
37
34
|
readonly visible?: boolean;
|
|
38
|
-
/** Box width relative to
|
|
35
|
+
/** Box width relative to stage area. 0~1. Default 0.5. */
|
|
39
36
|
readonly width?: number;
|
|
40
|
-
/** Box height relative to
|
|
37
|
+
/** Box height relative to stage area. 0~1. Default 0.5. */
|
|
41
38
|
readonly height?: number;
|
|
42
|
-
/** Minimum box width relative to
|
|
39
|
+
/** Minimum box width relative to stage area. 0~1. Default 0. */
|
|
43
40
|
readonly minWidth?: number;
|
|
44
|
-
/** Minimum box height relative to
|
|
41
|
+
/** Minimum box height relative to stage area. 0~1. Default 0. */
|
|
45
42
|
readonly minHeight?: number;
|
|
46
|
-
/** x position relative to
|
|
43
|
+
/** x position relative to stage area. 0~1. Default 0.1. */
|
|
47
44
|
readonly x?: number;
|
|
48
|
-
/** y position relative to
|
|
45
|
+
/** y position relative to stage area. 0~1. Default 0.1. */
|
|
49
46
|
readonly y?: number;
|
|
50
|
-
/** Maximize box. Default false. */
|
|
51
|
-
readonly maximized?: boolean;
|
|
52
|
-
/** Minimize box. Overwrites maximized state. Default false. */
|
|
53
|
-
readonly minimized?: boolean;
|
|
54
47
|
/** The initial state of the box. Default normal. */
|
|
55
48
|
readonly state?: TeleBoxState;
|
|
56
|
-
/** Is box readonly */
|
|
57
|
-
readonly readonly?: boolean;
|
|
58
49
|
/** Able to resize box window. Default true. */
|
|
59
50
|
readonly resizable?: boolean;
|
|
60
51
|
/** Able to drag box window Default true. */
|
|
61
52
|
readonly draggable?: boolean;
|
|
62
|
-
/**
|
|
63
|
-
readonly
|
|
64
|
-
/** Fixed width/height ratio for box window. Default false. */
|
|
65
|
-
readonly fixRatio?: boolean;
|
|
53
|
+
/** Fixed height/width ratio for box window. No ratio limit if <= 0. Default -1. */
|
|
54
|
+
readonly ratio?: number;
|
|
66
55
|
/** Box focused. */
|
|
67
56
|
readonly focus?: boolean;
|
|
68
57
|
/** Base z-index for box. */
|
|
69
58
|
readonly zIndex?: number;
|
|
59
|
+
/** Box stage ratio. Follow manager stage ratio if null. Default null. */
|
|
60
|
+
readonly stageRatio?: number | null;
|
|
70
61
|
/** Classname Prefix. For CSS styling. Default "telebox". */
|
|
71
62
|
readonly namespace?: string;
|
|
72
63
|
/** TeleTitleBar Instance. */
|
|
@@ -77,10 +68,30 @@ export interface TeleBoxConfig {
|
|
|
77
68
|
readonly footer?: HTMLElement;
|
|
78
69
|
/** Box content styles. */
|
|
79
70
|
readonly styles?: HTMLStyleElement;
|
|
80
|
-
/**
|
|
81
|
-
readonly
|
|
71
|
+
/** Show stage frame and grey-out the non-stage area. Inherit setting from manager if null. Default null. */
|
|
72
|
+
readonly highlightStage?: boolean | null;
|
|
73
|
+
/** Actual Box Dark Mode */
|
|
74
|
+
readonly darkMode$: ReadonlyVal<boolean, boolean>;
|
|
75
|
+
/** Restrict box to always be within the stage area. Default false. */
|
|
76
|
+
readonly fence$: ReadonlyVal<boolean, boolean>;
|
|
77
|
+
/** Maximize box. Default false. */
|
|
78
|
+
readonly maximized$: ReadonlyVal<boolean, boolean>;
|
|
79
|
+
/** Minimize box. Overwrites maximized state. Default false. */
|
|
80
|
+
readonly minimized$: ReadonlyVal<boolean, boolean>;
|
|
81
|
+
/** Is box readonly */
|
|
82
|
+
readonly readonly$: ReadonlyVal<boolean, boolean>;
|
|
83
|
+
/** Root element to mount boxes */
|
|
84
|
+
readonly root$: ReadonlyVal<HTMLElement | null>;
|
|
85
|
+
/** Position and dimension of root element */
|
|
86
|
+
readonly rootRect$: ReadonlyVal<TeleBoxRect>;
|
|
87
|
+
/** Position and dimension of stage area */
|
|
88
|
+
readonly managerStageRect$: ReadonlyVal<TeleBoxRect>;
|
|
89
|
+
/** Stage area height/with ratio. No ratio if <= 0. */
|
|
90
|
+
readonly managerStageRatio$: ReadonlyVal<number, boolean>;
|
|
82
91
|
/** Position and dimension of collector */
|
|
83
|
-
readonly collectorRect
|
|
92
|
+
readonly collectorRect$: ReadonlyVal<TeleBoxRect | undefined>;
|
|
93
|
+
/** highlight stage settings from manager */
|
|
94
|
+
readonly managerHighlightStage$: ReadonlyVal<boolean>;
|
|
84
95
|
}
|
|
85
96
|
|
|
86
97
|
type CheckTeleBoxConfig<T extends Record<`${TELE_BOX_EVENT}`, any>> = T;
|
|
@@ -88,44 +99,22 @@ type CheckTeleBoxConfig<T extends Record<`${TELE_BOX_EVENT}`, any>> = T;
|
|
|
88
99
|
export type TeleBoxEventConfig = CheckTeleBoxConfig<{
|
|
89
100
|
dark_mode: boolean;
|
|
90
101
|
prefers_color_scheme: TeleBoxColorScheme;
|
|
91
|
-
close:
|
|
92
|
-
focus:
|
|
93
|
-
blur:
|
|
94
|
-
move: { x: number; y: number };
|
|
95
|
-
resize: { width: number; height: number };
|
|
102
|
+
close: undefined;
|
|
103
|
+
focus: undefined;
|
|
104
|
+
blur: undefined;
|
|
96
105
|
intrinsic_move: { x: number; y: number };
|
|
97
106
|
intrinsic_resize: { width: number; height: number };
|
|
98
|
-
visual_resize: { width: number; height: number };
|
|
99
107
|
z_index: number;
|
|
100
108
|
state: TeleBoxState;
|
|
101
109
|
minimized: boolean;
|
|
102
110
|
maximized: boolean;
|
|
103
111
|
readonly: boolean;
|
|
104
|
-
destroyed:
|
|
112
|
+
destroyed: undefined;
|
|
105
113
|
}>;
|
|
106
114
|
|
|
107
115
|
export type TeleBoxEvent = keyof TeleBoxEventConfig;
|
|
108
116
|
|
|
109
|
-
export
|
|
110
|
-
on<U extends TeleBoxEvent>(
|
|
111
|
-
event: U,
|
|
112
|
-
listener: (value: TeleBoxEventConfig[U]) => void
|
|
113
|
-
): this;
|
|
114
|
-
once<U extends TeleBoxEvent>(
|
|
115
|
-
event: U,
|
|
116
|
-
listener: (value: TeleBoxEventConfig[U]) => void
|
|
117
|
-
): this;
|
|
118
|
-
addListener<U extends TeleBoxEvent>(
|
|
119
|
-
event: U,
|
|
120
|
-
listener: (value: TeleBoxEventConfig[U]) => void
|
|
121
|
-
): this;
|
|
122
|
-
emit<U extends TeleBoxEvent>(
|
|
123
|
-
event: U,
|
|
124
|
-
...value: TeleBoxEventConfig[U] extends void
|
|
125
|
-
? []
|
|
126
|
-
: [TeleBoxEventConfig[U]]
|
|
127
|
-
): boolean;
|
|
128
|
-
}
|
|
117
|
+
export type TeleBoxEvents = Emittery<TeleBoxEventConfig>;
|
|
129
118
|
|
|
130
119
|
export type TeleBoxHandleType =
|
|
131
120
|
| TELE_BOX_RESIZE_HANDLE
|
|
@@ -136,31 +125,11 @@ type CheckTeleBoxDelegateConfig<
|
|
|
136
125
|
> = T;
|
|
137
126
|
|
|
138
127
|
export type TeleBoxDelegateEventConfig = CheckTeleBoxDelegateConfig<{
|
|
139
|
-
close:
|
|
140
|
-
maximize:
|
|
141
|
-
minimize:
|
|
128
|
+
close: undefined;
|
|
129
|
+
maximize: undefined;
|
|
130
|
+
minimize: undefined;
|
|
142
131
|
}>;
|
|
143
132
|
|
|
144
133
|
export type TeleBoxDelegateEvent = keyof TeleBoxDelegateEventConfig;
|
|
145
134
|
|
|
146
|
-
export
|
|
147
|
-
extends EventEmitter<TeleBoxDelegateEvent> {
|
|
148
|
-
on<U extends TeleBoxDelegateEvent>(
|
|
149
|
-
event: U,
|
|
150
|
-
listener: (value: TeleBoxDelegateEventConfig[U]) => void
|
|
151
|
-
): this;
|
|
152
|
-
once<U extends TeleBoxDelegateEvent>(
|
|
153
|
-
event: U,
|
|
154
|
-
listener: (value: TeleBoxDelegateEventConfig[U]) => void
|
|
155
|
-
): this;
|
|
156
|
-
addListener<U extends TeleBoxDelegateEvent>(
|
|
157
|
-
event: U,
|
|
158
|
-
listener: (value: TeleBoxDelegateEventConfig[U]) => void
|
|
159
|
-
): this;
|
|
160
|
-
emit<U extends TeleBoxDelegateEvent>(
|
|
161
|
-
event: U,
|
|
162
|
-
...value: TeleBoxDelegateEventConfig[U] extends void
|
|
163
|
-
? []
|
|
164
|
-
: [TeleBoxDelegateEventConfig[U]]
|
|
165
|
-
): boolean;
|
|
166
|
-
}
|
|
135
|
+
export type TeleBoxDelegateEvents = Emittery<TeleBoxDelegateEventConfig>;
|
|
@@ -1,187 +1,179 @@
|
|
|
1
1
|
import "./style.scss";
|
|
2
2
|
import collectorSVG from "./icons/collector.svg";
|
|
3
|
-
import { TeleStyles } from "../typings";
|
|
3
|
+
import type { TeleStyles } from "../typings";
|
|
4
|
+
import type {
|
|
5
|
+
ReadonlyVal,
|
|
6
|
+
ReadonlyValEnhancedResult,
|
|
7
|
+
ValEnhancedResult,
|
|
8
|
+
} from "value-enhancer";
|
|
9
|
+
import { derive } from "value-enhancer";
|
|
10
|
+
import {
|
|
11
|
+
withValueEnhancer,
|
|
12
|
+
combine,
|
|
13
|
+
Val,
|
|
14
|
+
withReadonlyValueEnhancer,
|
|
15
|
+
ValManager,
|
|
16
|
+
} from "value-enhancer";
|
|
17
|
+
import { SideEffectManager } from "side-effect-manager";
|
|
18
|
+
import type { TeleBoxRect } from "../TeleBox/typings";
|
|
4
19
|
|
|
5
20
|
export interface TeleBoxCollectorConfig {
|
|
6
|
-
visible?: boolean;
|
|
7
|
-
readonly?: boolean;
|
|
8
|
-
darkMode?: boolean;
|
|
9
21
|
namespace?: string;
|
|
10
22
|
styles?: TeleStyles;
|
|
11
|
-
|
|
23
|
+
root$: ReadonlyVal<HTMLElement | null>;
|
|
24
|
+
minimized$: Val<boolean>;
|
|
25
|
+
readonly$: ReadonlyVal<boolean>;
|
|
26
|
+
darkMode$: ReadonlyVal<boolean>;
|
|
27
|
+
rootRect$: ReadonlyVal<TeleBoxRect>;
|
|
12
28
|
}
|
|
13
29
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
darkMode = false,
|
|
19
|
-
namespace = "telebox",
|
|
20
|
-
styles = {},
|
|
21
|
-
onClick,
|
|
22
|
-
}: TeleBoxCollectorConfig = {}) {
|
|
23
|
-
this._visible = visible;
|
|
24
|
-
this._readonly = readonly;
|
|
25
|
-
this._darkMode = darkMode;
|
|
26
|
-
this.namespace = namespace;
|
|
27
|
-
this.styles = styles;
|
|
28
|
-
this.onClick = onClick;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public readonly styles: TeleStyles;
|
|
32
|
-
|
|
33
|
-
public readonly namespace: string;
|
|
34
|
-
|
|
35
|
-
public get visible(): boolean {
|
|
36
|
-
return this._visible;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public get readonly(): boolean {
|
|
40
|
-
return this._readonly;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public get darkMode(): boolean {
|
|
44
|
-
return this._darkMode;
|
|
45
|
-
}
|
|
30
|
+
type ValConfig = {
|
|
31
|
+
styles: Val<TeleStyles>;
|
|
32
|
+
$collector: Val<HTMLElement>;
|
|
33
|
+
};
|
|
46
34
|
|
|
47
|
-
|
|
35
|
+
type PropsValConfig = {
|
|
36
|
+
root: TeleBoxCollectorConfig["root$"];
|
|
37
|
+
};
|
|
48
38
|
|
|
49
|
-
|
|
39
|
+
type MyReadonlyValConfig = {
|
|
40
|
+
rect: ReadonlyVal<TeleBoxRect | undefined>;
|
|
41
|
+
visible: ReadonlyVal<boolean>;
|
|
42
|
+
};
|
|
50
43
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*/
|
|
54
|
-
public mount(root: HTMLElement): this {
|
|
55
|
-
root.appendChild(this.render());
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
44
|
+
type CombinedValEnhancedResult = ValEnhancedResult<ValConfig> &
|
|
45
|
+
ReadonlyValEnhancedResult<PropsValConfig & MyReadonlyValConfig>;
|
|
58
46
|
|
|
59
|
-
|
|
60
|
-
* Unmount collector from the root element.
|
|
61
|
-
*/
|
|
62
|
-
public unmount(): this {
|
|
63
|
-
if (this.$collector) {
|
|
64
|
-
this.$collector.remove();
|
|
65
|
-
}
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
47
|
+
export interface TeleBoxCollector extends CombinedValEnhancedResult {}
|
|
68
48
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
49
|
+
export class TeleBoxCollector {
|
|
50
|
+
public constructor({
|
|
51
|
+
minimized$,
|
|
52
|
+
readonly$,
|
|
53
|
+
darkMode$,
|
|
54
|
+
rootRect$,
|
|
55
|
+
namespace = "telebox",
|
|
56
|
+
styles = {},
|
|
57
|
+
root$,
|
|
58
|
+
}: TeleBoxCollectorConfig) {
|
|
59
|
+
this.namespace = namespace;
|
|
81
60
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
61
|
+
const valManager = new ValManager();
|
|
62
|
+
this._sideEffect.addDisposer(() => valManager.destroy());
|
|
63
|
+
|
|
64
|
+
const rect$ = new Val<TeleBoxRect | undefined>(void 0);
|
|
65
|
+
const visible$ = derive(minimized$);
|
|
66
|
+
const styles$ = new Val(styles);
|
|
67
|
+
const el$ = new Val<HTMLElement>(document.createElement("button"));
|
|
68
|
+
|
|
69
|
+
const valConfig: ValConfig = {
|
|
70
|
+
styles: styles$,
|
|
71
|
+
$collector: el$,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
withValueEnhancer(this, valConfig, valManager);
|
|
75
|
+
|
|
76
|
+
const propsValConfig: PropsValConfig = {
|
|
77
|
+
root: root$,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
withReadonlyValueEnhancer(this, propsValConfig);
|
|
81
|
+
|
|
82
|
+
const myReadonlyValConfig: MyReadonlyValConfig = {
|
|
83
|
+
rect: rect$,
|
|
84
|
+
visible: visible$,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
|
|
88
|
+
|
|
89
|
+
el$.value.className = this.wrapClassName("collector");
|
|
90
|
+
el$.value.style.backgroundImage = `url('${collectorSVG}')`;
|
|
91
|
+
|
|
92
|
+
this._sideEffect.addDisposer(
|
|
93
|
+
el$.subscribe(($collector) => {
|
|
94
|
+
this._sideEffect.addEventListener(
|
|
95
|
+
$collector,
|
|
96
|
+
"click",
|
|
97
|
+
() => {
|
|
98
|
+
if (!readonly$.value) {
|
|
99
|
+
minimized$.setValue(false);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
{},
|
|
103
|
+
"telebox-collector-click"
|
|
89
104
|
);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
105
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
this._sideEffect.addDisposer(
|
|
107
|
+
[
|
|
108
|
+
visible$.subscribe((visible) => {
|
|
109
|
+
$collector.classList.toggle(
|
|
110
|
+
this.wrapClassName("collector-visible"),
|
|
111
|
+
visible
|
|
112
|
+
);
|
|
113
|
+
}),
|
|
114
|
+
readonly$.subscribe((readonly) => {
|
|
115
|
+
$collector.classList.toggle(
|
|
116
|
+
this.wrapClassName("collector-readonly"),
|
|
117
|
+
readonly
|
|
118
|
+
);
|
|
119
|
+
}),
|
|
120
|
+
darkMode$.subscribe((darkMode) => {
|
|
121
|
+
$collector.classList.toggle(
|
|
122
|
+
this.wrapClassName("color-scheme-dark"),
|
|
123
|
+
darkMode
|
|
124
|
+
);
|
|
125
|
+
$collector.classList.toggle(
|
|
126
|
+
this.wrapClassName("color-scheme-light"),
|
|
127
|
+
!darkMode
|
|
128
|
+
);
|
|
129
|
+
}),
|
|
130
|
+
styles$.subscribe((styles) => {
|
|
131
|
+
Object.keys(styles).forEach((key) => {
|
|
132
|
+
const value = styles[
|
|
133
|
+
key as keyof TeleStyles
|
|
134
|
+
] as string;
|
|
135
|
+
if (value != null) {
|
|
136
|
+
$collector.style[key as keyof TeleStyles] =
|
|
137
|
+
value;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}),
|
|
141
|
+
root$.subscribe((root) => {
|
|
142
|
+
if (root) {
|
|
143
|
+
root.appendChild($collector);
|
|
144
|
+
}
|
|
145
|
+
}),
|
|
146
|
+
// Place after $collector appended to the DOM so that rect calc works
|
|
147
|
+
combine([minimized$, rootRect$, root$]).subscribe(
|
|
148
|
+
([minimized, rootRect, root]) => {
|
|
149
|
+
if (minimized && root) {
|
|
150
|
+
const { x, y, width, height } =
|
|
151
|
+
$collector.getBoundingClientRect();
|
|
152
|
+
rect$.setValue({
|
|
153
|
+
x: x - rootRect.x,
|
|
154
|
+
y: y - rootRect.y,
|
|
155
|
+
width,
|
|
156
|
+
height,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
),
|
|
161
|
+
],
|
|
162
|
+
"telebox-collector-el"
|
|
102
163
|
);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
!darkMode
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public setStyles(styles: TeleStyles): this {
|
|
113
|
-
Object.assign(this.styles, styles);
|
|
114
|
-
if (this.$collector) {
|
|
115
|
-
const $collector = this.$collector;
|
|
116
|
-
Object.keys(styles).forEach((key) => {
|
|
117
|
-
const value = styles[key as keyof TeleStyles] as string;
|
|
118
|
-
if (value != null) {
|
|
119
|
-
$collector.style[key as keyof TeleStyles] = value;
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
return this;
|
|
164
|
+
})
|
|
165
|
+
);
|
|
124
166
|
}
|
|
125
167
|
|
|
126
|
-
public
|
|
127
|
-
if (!this.$collector) {
|
|
128
|
-
this.$collector = document.createElement("button");
|
|
129
|
-
this.$collector.className = this.wrapClassName("collector");
|
|
130
|
-
this.$collector.style.backgroundImage = `url('${collectorSVG}')`;
|
|
131
|
-
this.$collector.addEventListener(
|
|
132
|
-
"click",
|
|
133
|
-
this.handleCollectorClick
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
if (this._visible) {
|
|
137
|
-
this.$collector.classList.add(
|
|
138
|
-
this.wrapClassName("collector-visible")
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (this._readonly) {
|
|
143
|
-
this.$collector.classList.add(
|
|
144
|
-
this.wrapClassName("collector-readonly")
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
this.$collector.classList.add(
|
|
149
|
-
this.wrapClassName(
|
|
150
|
-
this._darkMode ? "color-scheme-dark" : "color-scheme-light"
|
|
151
|
-
)
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
this.setStyles(this.styles);
|
|
155
|
-
}
|
|
168
|
+
public readonly namespace: string;
|
|
156
169
|
|
|
157
|
-
|
|
158
|
-
}
|
|
170
|
+
protected readonly _sideEffect = new SideEffectManager();
|
|
159
171
|
|
|
160
172
|
public destroy(): void {
|
|
161
|
-
|
|
162
|
-
this.$collector.removeEventListener(
|
|
163
|
-
"click",
|
|
164
|
-
this.handleCollectorClick
|
|
165
|
-
);
|
|
166
|
-
this.$collector.remove();
|
|
167
|
-
this.$collector = void 0;
|
|
168
|
-
}
|
|
169
|
-
this.onClick = void 0;
|
|
173
|
+
this._sideEffect.flushAll();
|
|
170
174
|
}
|
|
171
175
|
|
|
172
176
|
public wrapClassName(className: string): string {
|
|
173
177
|
return `${this.namespace}-${className}`;
|
|
174
178
|
}
|
|
175
|
-
|
|
176
|
-
protected _visible: boolean;
|
|
177
|
-
|
|
178
|
-
protected _readonly: boolean;
|
|
179
|
-
|
|
180
|
-
protected _darkMode: boolean;
|
|
181
|
-
|
|
182
|
-
protected handleCollectorClick = (): void => {
|
|
183
|
-
if (!this._readonly && this.onClick) {
|
|
184
|
-
this.onClick();
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
179
|
}
|