@netless/telebox-insider 0.2.26 → 1.0.0-alpha.1
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 +120 -91
- package/dist/TeleBox/typings.d.ts +40 -55
- package/dist/TeleBoxCollector/index.d.ts +25 -29
- package/dist/TeleBoxManager/MaxTitleBar/index.d.ts +13 -18
- package/dist/TeleBoxManager/constants.d.ts +0 -3
- package/dist/TeleBoxManager/index.d.ts +55 -18
- package/dist/TeleBoxManager/typings.d.ts +35 -28
- package/dist/TeleStage/index.d.ts +25 -0
- package/dist/TeleTitleBar/DefaultTitleBar/index.d.ts +6 -8
- package/dist/TeleTitleBar/typings.d.ts +3 -5
- package/dist/index.d.ts +0 -1
- package/dist/style.css +1 -1
- package/dist/telebox-insider.cjs.js +2 -2
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +2 -2
- package/dist/telebox-insider.es.js.map +1 -1
- package/dist/utils.d.ts +0 -1
- package/package.json +6 -19
- package/src/TeleBox/constants.ts +0 -3
- package/src/TeleBox/index.ts +496 -678
- package/src/TeleBox/style.scss +1 -0
- package/src/TeleBox/typings.ts +40 -75
- package/src/TeleBoxCollector/index.ts +137 -159
- package/src/TeleBoxManager/MaxTitleBar/index.ts +82 -110
- package/src/TeleBoxManager/constants.ts +0 -3
- package/src/TeleBoxManager/index.ts +300 -326
- package/src/TeleBoxManager/typings.ts +42 -52
- package/src/TeleStage/index.ts +189 -0
- package/src/TeleStage/style.scss +49 -0
- package/src/TeleTitleBar/DefaultTitleBar/index.ts +48 -61
- package/src/TeleTitleBar/typings.ts +3 -9
- package/src/index.ts +0 -1
- 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,40 +30,28 @@ 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. */
|
|
@@ -77,10 +66,28 @@ export interface TeleBoxConfig {
|
|
|
77
66
|
readonly footer?: HTMLElement;
|
|
78
67
|
/** Box content styles. */
|
|
79
68
|
readonly styles?: HTMLStyleElement;
|
|
80
|
-
/**
|
|
81
|
-
readonly
|
|
69
|
+
/** Show stage frame and grey-out the non-stage area. Inherit setting from manager if null. Default null. */
|
|
70
|
+
readonly highlightStage?: boolean | null;
|
|
71
|
+
/** Actual Box Dark Mode */
|
|
72
|
+
readonly darkMode$: ReadonlyVal<boolean, boolean>;
|
|
73
|
+
/** Restrict box to always be within the stage area. Default false. */
|
|
74
|
+
readonly fence$: ReadonlyVal<boolean, boolean>;
|
|
75
|
+
/** Maximize box. Default false. */
|
|
76
|
+
readonly maximized$: ReadonlyVal<boolean, boolean>;
|
|
77
|
+
/** Minimize box. Overwrites maximized state. Default false. */
|
|
78
|
+
readonly minimized$: ReadonlyVal<boolean, boolean>;
|
|
79
|
+
/** Is box readonly */
|
|
80
|
+
readonly readonly$: ReadonlyVal<boolean, boolean>;
|
|
81
|
+
/** Position and dimension of root element */
|
|
82
|
+
readonly rootRect$: ReadonlyVal<TeleBoxRect>;
|
|
83
|
+
/** Position and dimension of stage area */
|
|
84
|
+
readonly managerStageRect$: ReadonlyVal<TeleBoxRect>;
|
|
85
|
+
/** Stage area height/with ratio. No ratio if <= 0. */
|
|
86
|
+
readonly stageRatio$: ReadonlyVal<number, boolean>;
|
|
82
87
|
/** Position and dimension of collector */
|
|
83
|
-
readonly collectorRect
|
|
88
|
+
readonly collectorRect$: ReadonlyVal<TeleBoxRect | undefined>;
|
|
89
|
+
/** highlight stage settings from manager */
|
|
90
|
+
readonly managerHighlightStage$: ReadonlyVal<boolean>;
|
|
84
91
|
}
|
|
85
92
|
|
|
86
93
|
type CheckTeleBoxConfig<T extends Record<`${TELE_BOX_EVENT}`, any>> = T;
|
|
@@ -88,44 +95,22 @@ type CheckTeleBoxConfig<T extends Record<`${TELE_BOX_EVENT}`, any>> = T;
|
|
|
88
95
|
export type TeleBoxEventConfig = CheckTeleBoxConfig<{
|
|
89
96
|
dark_mode: boolean;
|
|
90
97
|
prefers_color_scheme: TeleBoxColorScheme;
|
|
91
|
-
close:
|
|
92
|
-
focus:
|
|
93
|
-
blur:
|
|
94
|
-
move: { x: number; y: number };
|
|
95
|
-
resize: { width: number; height: number };
|
|
98
|
+
close: undefined;
|
|
99
|
+
focus: undefined;
|
|
100
|
+
blur: undefined;
|
|
96
101
|
intrinsic_move: { x: number; y: number };
|
|
97
102
|
intrinsic_resize: { width: number; height: number };
|
|
98
|
-
visual_resize: { width: number; height: number };
|
|
99
103
|
z_index: number;
|
|
100
104
|
state: TeleBoxState;
|
|
101
105
|
minimized: boolean;
|
|
102
106
|
maximized: boolean;
|
|
103
107
|
readonly: boolean;
|
|
104
|
-
destroyed:
|
|
108
|
+
destroyed: undefined;
|
|
105
109
|
}>;
|
|
106
110
|
|
|
107
111
|
export type TeleBoxEvent = keyof TeleBoxEventConfig;
|
|
108
112
|
|
|
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
|
-
}
|
|
113
|
+
export type TeleBoxEvents = Emittery<TeleBoxEventConfig>;
|
|
129
114
|
|
|
130
115
|
export type TeleBoxHandleType =
|
|
131
116
|
| TELE_BOX_RESIZE_HANDLE
|
|
@@ -136,31 +121,11 @@ type CheckTeleBoxDelegateConfig<
|
|
|
136
121
|
> = T;
|
|
137
122
|
|
|
138
123
|
export type TeleBoxDelegateEventConfig = CheckTeleBoxDelegateConfig<{
|
|
139
|
-
close:
|
|
140
|
-
maximize:
|
|
141
|
-
minimize:
|
|
124
|
+
close: undefined;
|
|
125
|
+
maximize: undefined;
|
|
126
|
+
minimize: undefined;
|
|
142
127
|
}>;
|
|
143
128
|
|
|
144
129
|
export type TeleBoxDelegateEvent = keyof TeleBoxDelegateEventConfig;
|
|
145
130
|
|
|
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
|
-
}
|
|
131
|
+
export type TeleBoxDelegateEvents = Emittery<TeleBoxDelegateEventConfig>;
|
|
@@ -1,187 +1,165 @@
|
|
|
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 { withValueEnhancer } from "value-enhancer";
|
|
10
|
+
import { combine } from "value-enhancer";
|
|
11
|
+
import { Val } from "value-enhancer";
|
|
12
|
+
import { withReadonlyValueEnhancer } from "value-enhancer";
|
|
13
|
+
import { SideEffectManager } from "side-effect-manager";
|
|
14
|
+
import type { TeleBoxRect } from "../TeleBox/typings";
|
|
4
15
|
|
|
5
16
|
export interface TeleBoxCollectorConfig {
|
|
6
|
-
visible?: boolean;
|
|
7
|
-
readonly?: boolean;
|
|
8
|
-
darkMode?: boolean;
|
|
9
17
|
namespace?: string;
|
|
10
18
|
styles?: TeleStyles;
|
|
11
|
-
|
|
19
|
+
root?: HTMLElement;
|
|
20
|
+
minimized$: Val<boolean>;
|
|
21
|
+
readonly$: ReadonlyVal<boolean>;
|
|
22
|
+
darkMode$: ReadonlyVal<boolean>;
|
|
23
|
+
rootRect$: ReadonlyVal<TeleBoxRect>;
|
|
12
24
|
}
|
|
13
25
|
|
|
26
|
+
type ValConfig = {
|
|
27
|
+
styles: Val<TeleStyles>;
|
|
28
|
+
root: Val<HTMLElement | undefined>;
|
|
29
|
+
el: Val<HTMLElement>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type ReadonlyValConfig = {
|
|
33
|
+
rect: ReadonlyVal<TeleBoxRect | undefined>;
|
|
34
|
+
visible: ReadonlyVal<boolean>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type CombinedValEnhancedResult = ValEnhancedResult<ValConfig> &
|
|
38
|
+
ReadonlyValEnhancedResult<ReadonlyValConfig>;
|
|
39
|
+
|
|
40
|
+
export interface TeleBoxCollector extends CombinedValEnhancedResult {}
|
|
41
|
+
|
|
14
42
|
export class TeleBoxCollector {
|
|
15
43
|
public constructor({
|
|
16
|
-
|
|
17
|
-
readonly
|
|
18
|
-
darkMode
|
|
44
|
+
minimized$,
|
|
45
|
+
readonly$,
|
|
46
|
+
darkMode$,
|
|
47
|
+
rootRect$,
|
|
19
48
|
namespace = "telebox",
|
|
20
49
|
styles = {},
|
|
21
|
-
|
|
22
|
-
}: TeleBoxCollectorConfig
|
|
23
|
-
this._visible = visible;
|
|
24
|
-
this._readonly = readonly;
|
|
25
|
-
this._darkMode = darkMode;
|
|
50
|
+
root,
|
|
51
|
+
}: TeleBoxCollectorConfig) {
|
|
26
52
|
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
|
-
}
|
|
46
|
-
|
|
47
|
-
public onClick: (() => void) | undefined;
|
|
48
|
-
|
|
49
|
-
public $collector: HTMLElement | undefined;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Mount collector to a root element.
|
|
53
|
-
*/
|
|
54
|
-
public mount(root: HTMLElement): this {
|
|
55
|
-
root.appendChild(this.render());
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
|
|
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
|
-
}
|
|
68
53
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
54
|
+
const rect$ = new Val<TeleBoxRect | undefined>(void 0);
|
|
55
|
+
const visible$ = minimized$;
|
|
56
|
+
const styles$ = new Val(styles);
|
|
57
|
+
const root$ = new Val(root);
|
|
58
|
+
const el$ = new Val<HTMLElement>(document.createElement("button"));
|
|
59
|
+
|
|
60
|
+
const valConfig: ValConfig = {
|
|
61
|
+
styles: styles$,
|
|
62
|
+
root: root$,
|
|
63
|
+
el: el$,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
withValueEnhancer(this, valConfig);
|
|
67
|
+
|
|
68
|
+
const readonlyValConfig: ReadonlyValConfig = {
|
|
69
|
+
rect: rect$,
|
|
70
|
+
visible: visible$,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
withReadonlyValueEnhancer(this, readonlyValConfig);
|
|
74
|
+
|
|
75
|
+
el$.value.className = this.wrapClassName("collector");
|
|
76
|
+
el$.value.style.backgroundImage = `url('${collectorSVG}')`;
|
|
77
|
+
|
|
78
|
+
this._sideEffect.addDisposer(
|
|
79
|
+
el$.subscribe(($collector) => {
|
|
80
|
+
this._sideEffect.addEventListener(
|
|
81
|
+
$collector,
|
|
82
|
+
"click",
|
|
83
|
+
() => {
|
|
84
|
+
if (!readonly$.value) {
|
|
85
|
+
minimized$.setValue(false);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{},
|
|
89
|
+
"telebox-collector-click"
|
|
76
90
|
);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public setReadonly(readonly: boolean): this {
|
|
83
|
-
if (this._readonly !== readonly) {
|
|
84
|
-
this._readonly = readonly;
|
|
85
|
-
if (this.$collector) {
|
|
86
|
-
this.$collector.classList.toggle(
|
|
87
|
-
this.wrapClassName("collector-readonly"),
|
|
88
|
-
readonly
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
91
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
this._sideEffect.addDisposer(
|
|
93
|
+
[
|
|
94
|
+
visible$.subscribe((visible) => {
|
|
95
|
+
$collector.classList.toggle(
|
|
96
|
+
this.wrapClassName("collector-visible"),
|
|
97
|
+
visible
|
|
98
|
+
);
|
|
99
|
+
}),
|
|
100
|
+
readonly$.subscribe((readonly) => {
|
|
101
|
+
$collector.classList.toggle(
|
|
102
|
+
this.wrapClassName("collector-readonly"),
|
|
103
|
+
readonly
|
|
104
|
+
);
|
|
105
|
+
}),
|
|
106
|
+
darkMode$.subscribe((darkMode) => {
|
|
107
|
+
$collector.classList.toggle(
|
|
108
|
+
this.wrapClassName("color-scheme-dark"),
|
|
109
|
+
darkMode
|
|
110
|
+
);
|
|
111
|
+
$collector.classList.toggle(
|
|
112
|
+
this.wrapClassName("color-scheme-light"),
|
|
113
|
+
!darkMode
|
|
114
|
+
);
|
|
115
|
+
}),
|
|
116
|
+
styles$.subscribe((styles) => {
|
|
117
|
+
Object.keys(styles).forEach((key) => {
|
|
118
|
+
const value = styles[
|
|
119
|
+
key as keyof TeleStyles
|
|
120
|
+
] as string;
|
|
121
|
+
if (value != null) {
|
|
122
|
+
$collector.style[key as keyof TeleStyles] =
|
|
123
|
+
value;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}),
|
|
127
|
+
root$.subscribe((root) => {
|
|
128
|
+
if (root) {
|
|
129
|
+
root.appendChild($collector);
|
|
130
|
+
}
|
|
131
|
+
}),
|
|
132
|
+
// Place after $collector appended to the DOM so that rect calc works
|
|
133
|
+
combine([minimized$, rootRect$, root$]).subscribe(
|
|
134
|
+
([minimized, rootRect, root]) => {
|
|
135
|
+
if (minimized && root) {
|
|
136
|
+
const { x, y, width, height } =
|
|
137
|
+
$collector.getBoundingClientRect();
|
|
138
|
+
rect$.setValue({
|
|
139
|
+
x: x - rootRect.x,
|
|
140
|
+
y: y - rootRect.y,
|
|
141
|
+
width,
|
|
142
|
+
height,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
),
|
|
147
|
+
],
|
|
148
|
+
"telebox-collector-el"
|
|
102
149
|
);
|
|
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;
|
|
150
|
+
})
|
|
151
|
+
);
|
|
124
152
|
}
|
|
125
153
|
|
|
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
|
-
}
|
|
154
|
+
public readonly namespace: string;
|
|
156
155
|
|
|
157
|
-
|
|
158
|
-
}
|
|
156
|
+
protected readonly _sideEffect = new SideEffectManager();
|
|
159
157
|
|
|
160
158
|
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;
|
|
159
|
+
this._sideEffect.flushAll();
|
|
170
160
|
}
|
|
171
161
|
|
|
172
162
|
public wrapClassName(className: string): string {
|
|
173
163
|
return `${this.namespace}-${className}`;
|
|
174
164
|
}
|
|
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
165
|
}
|