@netless/telebox-insider 0.2.0 → 0.2.4
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 +2 -0
- package/dist/TeleBox/index.d.ts +40 -69
- package/dist/TeleBox/typings.d.ts +2 -0
- package/dist/TeleBoxManager/constants.d.ts +2 -0
- package/dist/TeleBoxManager/index.d.ts +14 -23
- package/dist/TeleBoxManager/typings.d.ts +2 -0
- 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/package.json +4 -3
- package/src/TeleBox/constants.ts +2 -0
- package/src/TeleBox/index.ts +194 -315
- package/src/TeleBox/typings.ts +2 -0
- package/src/TeleBoxManager/constants.ts +2 -0
- package/src/TeleBoxManager/index.ts +100 -130
- package/src/TeleBoxManager/typings.ts +2 -0
- package/dist/Val/CombinedVal.d.ts +0 -11
- package/dist/Val/ComputedVal.d.ts +0 -7
- package/dist/Val/Val.d.ts +0 -15
- package/dist/Val/index.d.ts +0 -3
- package/src/Val/CombinedVal.ts +0 -39
- package/src/Val/ComputedVal.ts +0 -28
- package/src/Val/Val.ts +0 -73
- package/src/Val/index.ts +0 -3
package/src/TeleBox/index.ts
CHANGED
|
@@ -3,6 +3,14 @@ import "./style.scss";
|
|
|
3
3
|
import EventEmitter from "eventemitter3";
|
|
4
4
|
import styler from "stylefire";
|
|
5
5
|
import shallowequal from "shallowequal";
|
|
6
|
+
import { SideEffectManager } from "side-effect-manager";
|
|
7
|
+
import {
|
|
8
|
+
createSideEffectBinder,
|
|
9
|
+
Val,
|
|
10
|
+
ValEnhancedResult,
|
|
11
|
+
ValSideEffectBinder,
|
|
12
|
+
withValueEnhancer,
|
|
13
|
+
} from "value-enhancer";
|
|
6
14
|
import { DefaultTitleBar, TeleTitleBar } from "../TeleTitleBar";
|
|
7
15
|
import {
|
|
8
16
|
clamp,
|
|
@@ -29,12 +37,39 @@ import type {
|
|
|
29
37
|
TeleBoxCoord,
|
|
30
38
|
TeleBoxSize,
|
|
31
39
|
} from "./typings";
|
|
32
|
-
import { SideEffectManager } from "side-effect-manager";
|
|
33
|
-
import { Val, CombinedVal } from "../Val";
|
|
34
40
|
|
|
35
41
|
export * from "./constants";
|
|
36
42
|
export * from "./typings";
|
|
37
43
|
|
|
44
|
+
type ValConfig = {
|
|
45
|
+
containerRect: Val<TeleBoxRect, boolean>;
|
|
46
|
+
collectorRect: Val<TeleBoxRect | undefined, boolean>;
|
|
47
|
+
/** Box title. Default empty. */
|
|
48
|
+
title: Val<string, boolean>;
|
|
49
|
+
/** Is box visible */
|
|
50
|
+
visible: Val<boolean, boolean>;
|
|
51
|
+
/** Is box readonly */
|
|
52
|
+
readonly: Val<boolean, boolean>;
|
|
53
|
+
/** Able to resize box window */
|
|
54
|
+
resizable: Val<boolean, boolean>;
|
|
55
|
+
/** Able to drag box window */
|
|
56
|
+
draggable: Val<boolean, boolean>;
|
|
57
|
+
/** Restrict box to always be within the containing area. */
|
|
58
|
+
fence: Val<boolean, boolean>;
|
|
59
|
+
/** Fixed width/height ratio for box window. */
|
|
60
|
+
fixRatio: Val<boolean, boolean>;
|
|
61
|
+
focus: Val<boolean, boolean>;
|
|
62
|
+
zIndex: Val<number, boolean>;
|
|
63
|
+
/** Is box minimized. Default false. */
|
|
64
|
+
minimized: Val<boolean, boolean>;
|
|
65
|
+
/** Is box maximized. Default false. */
|
|
66
|
+
maximized: Val<boolean, boolean>;
|
|
67
|
+
$userContent: Val<HTMLElement | undefined>;
|
|
68
|
+
$userFooter: Val<HTMLElement | undefined>;
|
|
69
|
+
$userStyles: Val<HTMLStyleElement | undefined>;
|
|
70
|
+
};
|
|
71
|
+
export interface TeleBox extends ValEnhancedResult<ValConfig> {}
|
|
72
|
+
|
|
38
73
|
export class TeleBox {
|
|
39
74
|
public constructor({
|
|
40
75
|
id = genUniqueKey(),
|
|
@@ -69,39 +104,41 @@ export class TeleBox {
|
|
|
69
104
|
collectorRect,
|
|
70
105
|
}: TeleBoxConfig = {}) {
|
|
71
106
|
this._sideEffect = new SideEffectManager();
|
|
107
|
+
this._valSideEffectBinder = createSideEffectBinder(this._sideEffect);
|
|
108
|
+
const { combine, createVal } = this._valSideEffectBinder;
|
|
72
109
|
|
|
73
110
|
this.id = id;
|
|
74
111
|
this.namespace = namespace;
|
|
75
112
|
this.events = new EventEmitter();
|
|
76
113
|
this._delegateEvents = new EventEmitter();
|
|
77
114
|
|
|
78
|
-
|
|
79
|
-
|
|
115
|
+
const containerRect$ = createVal(containerRect, shallowequal);
|
|
116
|
+
const collectorRect$ = createVal(collectorRect, shallowequal);
|
|
80
117
|
|
|
81
|
-
|
|
118
|
+
const title$ = createVal(title);
|
|
82
119
|
|
|
83
|
-
|
|
84
|
-
|
|
120
|
+
const visible$ = createVal(visible);
|
|
121
|
+
visible$.reaction((visible, _, skipUpdate) => {
|
|
85
122
|
if (!skipUpdate && !visible) {
|
|
86
123
|
this.events.emit(TELE_BOX_EVENT.Close);
|
|
87
124
|
}
|
|
88
125
|
});
|
|
89
126
|
|
|
90
|
-
|
|
91
|
-
|
|
127
|
+
const readonly$ = createVal(readonly);
|
|
128
|
+
readonly$.reaction((readonly, _, skipUpdate) => {
|
|
92
129
|
if (!skipUpdate) {
|
|
93
130
|
this.events.emit(TELE_BOX_EVENT.Readonly, readonly);
|
|
94
131
|
}
|
|
95
132
|
});
|
|
96
133
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
134
|
+
const resizable$ = createVal(resizable);
|
|
135
|
+
const draggable$ = createVal(draggable);
|
|
136
|
+
const fence$ = createVal(fence);
|
|
137
|
+
const fixRatio$ = createVal(fixRatio);
|
|
138
|
+
const zIndex$ = createVal(zIndex);
|
|
102
139
|
|
|
103
|
-
|
|
104
|
-
|
|
140
|
+
const focus$ = createVal(focus);
|
|
141
|
+
focus$.reaction((focus, _, skipUpdate) => {
|
|
105
142
|
if (!skipUpdate) {
|
|
106
143
|
this.events.emit(
|
|
107
144
|
focus ? TELE_BOX_EVENT.Focus : TELE_BOX_EVENT.Blur
|
|
@@ -109,11 +146,22 @@ export class TeleBox {
|
|
|
109
146
|
}
|
|
110
147
|
});
|
|
111
148
|
|
|
112
|
-
|
|
113
|
-
|
|
149
|
+
const minimized$ = createVal(minimized);
|
|
150
|
+
minimized$.reaction((minimized, _, skipUpdate) => {
|
|
151
|
+
if (!skipUpdate) {
|
|
152
|
+
this.events.emit(TELE_BOX_EVENT.Minimized, minimized);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const maximized$ = createVal(maximized);
|
|
157
|
+
maximized$.reaction((maximized, _, skipUpdate) => {
|
|
158
|
+
if (!skipUpdate) {
|
|
159
|
+
this.events.emit(TELE_BOX_EVENT.Maximized, maximized);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
114
162
|
|
|
115
|
-
|
|
116
|
-
[
|
|
163
|
+
const state$ = combine(
|
|
164
|
+
[minimized$, maximized$],
|
|
117
165
|
([minimized, maximized]): TeleBoxState =>
|
|
118
166
|
minimized
|
|
119
167
|
? TELE_BOX_STATE.Minimized
|
|
@@ -121,13 +169,13 @@ export class TeleBox {
|
|
|
121
169
|
? TELE_BOX_STATE.Maximized
|
|
122
170
|
: TELE_BOX_STATE.Normal
|
|
123
171
|
);
|
|
124
|
-
|
|
172
|
+
state$.reaction((state, _, skipUpdate) => {
|
|
125
173
|
if (!skipUpdate) {
|
|
126
174
|
this.events.emit(TELE_BOX_EVENT.State, state);
|
|
127
175
|
}
|
|
128
176
|
});
|
|
129
177
|
|
|
130
|
-
|
|
178
|
+
const minSize$ = createVal(
|
|
131
179
|
{
|
|
132
180
|
width: clamp(minWidth, 0, 1),
|
|
133
181
|
height: clamp(minHeight, 0, 1),
|
|
@@ -135,15 +183,15 @@ export class TeleBox {
|
|
|
135
183
|
shallowequal
|
|
136
184
|
);
|
|
137
185
|
|
|
138
|
-
|
|
186
|
+
const intrinsicSize$ = createVal(
|
|
139
187
|
{
|
|
140
|
-
width: clamp(width,
|
|
141
|
-
height: clamp(height,
|
|
188
|
+
width: clamp(width, minSize$.value.width, 1),
|
|
189
|
+
height: clamp(height, minSize$.value.height, 1),
|
|
142
190
|
},
|
|
143
191
|
shallowequal
|
|
144
192
|
);
|
|
145
|
-
|
|
146
|
-
|
|
193
|
+
minSize$.reaction((minSize, _, skipUpdate) => {
|
|
194
|
+
intrinsicSize$.setValue(
|
|
147
195
|
{
|
|
148
196
|
width: clamp(width, minSize.width, 1),
|
|
149
197
|
height: clamp(height, minSize.height, 1),
|
|
@@ -151,14 +199,14 @@ export class TeleBox {
|
|
|
151
199
|
skipUpdate
|
|
152
200
|
);
|
|
153
201
|
});
|
|
154
|
-
|
|
202
|
+
intrinsicSize$.reaction((size, _, skipUpdate) => {
|
|
155
203
|
if (!skipUpdate) {
|
|
156
204
|
this.events.emit(TELE_BOX_EVENT.IntrinsicResize, size);
|
|
157
205
|
}
|
|
158
206
|
});
|
|
159
207
|
|
|
160
|
-
|
|
161
|
-
[
|
|
208
|
+
const size$ = combine(
|
|
209
|
+
[intrinsicSize$, maximized$],
|
|
162
210
|
([intrinsicSize, maximized]) => {
|
|
163
211
|
if (maximized) {
|
|
164
212
|
return { width: 1, height: 1 };
|
|
@@ -167,19 +215,14 @@ export class TeleBox {
|
|
|
167
215
|
},
|
|
168
216
|
shallowequal
|
|
169
217
|
);
|
|
170
|
-
|
|
218
|
+
size$.reaction((size, _, skipUpdate) => {
|
|
171
219
|
if (!skipUpdate) {
|
|
172
220
|
this.events.emit(TELE_BOX_EVENT.Resize, size);
|
|
173
221
|
}
|
|
174
222
|
});
|
|
175
223
|
|
|
176
|
-
|
|
177
|
-
[
|
|
178
|
-
this._size,
|
|
179
|
-
this._minimized,
|
|
180
|
-
this._containerRect,
|
|
181
|
-
this._collectorRect,
|
|
182
|
-
],
|
|
224
|
+
const visualSize$ = combine(
|
|
225
|
+
[size$, minimized$, containerRect$, collectorRect$],
|
|
183
226
|
([size, minimized, containerRect, collectorRect]) => {
|
|
184
227
|
if (minimized && collectorRect) {
|
|
185
228
|
return {
|
|
@@ -197,30 +240,30 @@ export class TeleBox {
|
|
|
197
240
|
},
|
|
198
241
|
shallowequal
|
|
199
242
|
);
|
|
200
|
-
|
|
243
|
+
visualSize$.reaction((size, _, skipUpdate) => {
|
|
201
244
|
if (!skipUpdate) {
|
|
202
245
|
this.events.emit(TELE_BOX_EVENT.VisualResize, size);
|
|
203
246
|
}
|
|
204
247
|
});
|
|
205
248
|
|
|
206
|
-
|
|
249
|
+
const intrinsicCoord$ = createVal(
|
|
207
250
|
{ x: clamp(x, 0, 1), y: clamp(y, 0, 1) },
|
|
208
251
|
shallowequal
|
|
209
252
|
);
|
|
210
|
-
|
|
253
|
+
intrinsicCoord$.reaction((coord, _, skipUpdate) => {
|
|
211
254
|
if (!skipUpdate) {
|
|
212
255
|
this.events.emit(TELE_BOX_EVENT.IntrinsicMove, coord);
|
|
213
256
|
}
|
|
214
257
|
});
|
|
215
258
|
|
|
216
|
-
|
|
259
|
+
const coord$ = combine(
|
|
217
260
|
[
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
261
|
+
intrinsicCoord$,
|
|
262
|
+
intrinsicSize$,
|
|
263
|
+
containerRect$,
|
|
264
|
+
collectorRect$,
|
|
265
|
+
minimized$,
|
|
266
|
+
maximized$,
|
|
224
267
|
],
|
|
225
268
|
([
|
|
226
269
|
intrinsicCoord,
|
|
@@ -261,7 +304,7 @@ export class TeleBox {
|
|
|
261
304
|
},
|
|
262
305
|
shallowequal
|
|
263
306
|
);
|
|
264
|
-
|
|
307
|
+
coord$.reaction((coord, _, skipUpdate) => {
|
|
265
308
|
if (!skipUpdate) {
|
|
266
309
|
this.events.emit(TELE_BOX_EVENT.Move, coord);
|
|
267
310
|
}
|
|
@@ -270,8 +313,8 @@ export class TeleBox {
|
|
|
270
313
|
this.titleBar =
|
|
271
314
|
titleBar ||
|
|
272
315
|
new DefaultTitleBar({
|
|
273
|
-
readonly:
|
|
274
|
-
title:
|
|
316
|
+
readonly: readonly$.value,
|
|
317
|
+
title: title$.value,
|
|
275
318
|
namespace: this.namespace,
|
|
276
319
|
onDragStart: (event) => this._handleTrackStart?.(event),
|
|
277
320
|
onEvent: (event): void => {
|
|
@@ -280,15 +323,15 @@ export class TeleBox {
|
|
|
280
323
|
} else {
|
|
281
324
|
switch (event.type) {
|
|
282
325
|
case TELE_BOX_DELEGATE_EVENT.Maximize: {
|
|
283
|
-
|
|
326
|
+
maximized$.setValue(!maximized$.value);
|
|
284
327
|
break;
|
|
285
328
|
}
|
|
286
329
|
case TELE_BOX_DELEGATE_EVENT.Minimize: {
|
|
287
|
-
|
|
330
|
+
minimized$.setValue(true);
|
|
288
331
|
break;
|
|
289
332
|
}
|
|
290
333
|
case TELE_BOX_DELEGATE_EVENT.Close: {
|
|
291
|
-
|
|
334
|
+
visible$.setValue(false);
|
|
292
335
|
break;
|
|
293
336
|
}
|
|
294
337
|
default: {
|
|
@@ -302,16 +345,51 @@ export class TeleBox {
|
|
|
302
345
|
}
|
|
303
346
|
},
|
|
304
347
|
});
|
|
305
|
-
|
|
348
|
+
readonly$.reaction((readonly) => {
|
|
306
349
|
this.titleBar.setReadonly(readonly);
|
|
307
350
|
});
|
|
308
351
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
352
|
+
const $userContent$ = createVal(content);
|
|
353
|
+
const $userFooter$ = createVal(footer);
|
|
354
|
+
const $userStyles$ = createVal(styles);
|
|
355
|
+
|
|
356
|
+
const valConfig: ValConfig = {
|
|
357
|
+
containerRect: containerRect$,
|
|
358
|
+
collectorRect: collectorRect$,
|
|
359
|
+
title: title$,
|
|
360
|
+
visible: visible$,
|
|
361
|
+
readonly: readonly$,
|
|
362
|
+
resizable: resizable$,
|
|
363
|
+
draggable: draggable$,
|
|
364
|
+
fence: fence$,
|
|
365
|
+
fixRatio: fixRatio$,
|
|
366
|
+
focus: focus$,
|
|
367
|
+
zIndex: zIndex$,
|
|
368
|
+
minimized: minimized$,
|
|
369
|
+
maximized: maximized$,
|
|
370
|
+
$userContent: $userContent$,
|
|
371
|
+
$userFooter: $userFooter$,
|
|
372
|
+
$userStyles: $userStyles$,
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
withValueEnhancer(this, valConfig);
|
|
376
|
+
|
|
377
|
+
this._state$ = state$;
|
|
378
|
+
this._minSize$ = minSize$;
|
|
379
|
+
this._size$ = size$;
|
|
380
|
+
this._intrinsicSize$ = intrinsicSize$;
|
|
381
|
+
this._visualSize$ = visualSize$;
|
|
382
|
+
this._coord$ = coord$;
|
|
383
|
+
this._intrinsicCoord$ = intrinsicCoord$;
|
|
312
384
|
|
|
313
385
|
if (this.fixRatio) {
|
|
314
|
-
this.transform(
|
|
386
|
+
this.transform(
|
|
387
|
+
coord$.value.x,
|
|
388
|
+
coord$.value.y,
|
|
389
|
+
size$.value.width,
|
|
390
|
+
size$.value.height,
|
|
391
|
+
true
|
|
392
|
+
);
|
|
315
393
|
}
|
|
316
394
|
|
|
317
395
|
this.$box = this.render();
|
|
@@ -319,7 +397,7 @@ export class TeleBox {
|
|
|
319
397
|
|
|
320
398
|
public readonly id: string;
|
|
321
399
|
|
|
322
|
-
/**
|
|
400
|
+
/** ClassName Prefix. For CSS styling. Default "telebox" */
|
|
323
401
|
public readonly namespace: string;
|
|
324
402
|
|
|
325
403
|
public readonly events: TeleBoxEvents;
|
|
@@ -328,167 +406,21 @@ export class TeleBox {
|
|
|
328
406
|
|
|
329
407
|
protected _sideEffect: SideEffectManager;
|
|
330
408
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
protected _containerRect: Val<TeleBoxRect, boolean>;
|
|
334
|
-
|
|
335
|
-
public get containerRect(): TeleBoxRect {
|
|
336
|
-
return this._containerRect.value;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
public setContainerRect(rect: TeleBoxRect, skipUpdate = false): this {
|
|
340
|
-
this._containerRect.setValue(rect, skipUpdate);
|
|
341
|
-
return this;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
protected _collectorRect: Val<TeleBoxRect | undefined, boolean>;
|
|
345
|
-
|
|
346
|
-
public get collectorRect(): TeleBoxRect | undefined {
|
|
347
|
-
return this._collectorRect.value;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
public setCollectorRect(rect: TeleBoxRect, skipUpdate = false): this {
|
|
351
|
-
this._collectorRect.setValue(rect, skipUpdate);
|
|
352
|
-
return this;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
protected _title: Val<string, boolean>;
|
|
356
|
-
|
|
357
|
-
/** Box title. Default empty. */
|
|
358
|
-
public get title(): string {
|
|
359
|
-
return this._title.value;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Update box title.
|
|
364
|
-
* @param title new box title
|
|
365
|
-
* @returns this
|
|
366
|
-
*/
|
|
367
|
-
public setTitle(title: string): this {
|
|
368
|
-
this._title.setValue(title);
|
|
369
|
-
return this;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
protected _visible: Val<boolean, boolean>;
|
|
373
|
-
|
|
374
|
-
public get visible(): boolean {
|
|
375
|
-
return this._visible.value;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
public setVisible(visible: boolean, skipUpdate = false): this {
|
|
379
|
-
this._visible.setValue(visible, skipUpdate);
|
|
380
|
-
return this;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
protected _readonly: Val<boolean, boolean>;
|
|
384
|
-
|
|
385
|
-
/** Is box readonly */
|
|
386
|
-
public get readonly(): boolean {
|
|
387
|
-
return this._readonly.value;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
public setReadonly(readonly: boolean, skipUpdate = false): this {
|
|
391
|
-
this._readonly.setValue(readonly, skipUpdate);
|
|
392
|
-
return this;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
protected _resizable: Val<boolean, boolean>;
|
|
396
|
-
|
|
397
|
-
/** Able to resize box window */
|
|
398
|
-
public get resizable(): boolean {
|
|
399
|
-
return this._resizable.value;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
public setResizable(resizable: boolean, skipUpdate = false): this {
|
|
403
|
-
this._resizable.setValue(resizable, skipUpdate);
|
|
404
|
-
return this;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
protected _draggable: Val<boolean, boolean>;
|
|
408
|
-
|
|
409
|
-
/** Able to drag box window */
|
|
410
|
-
public get draggable(): boolean {
|
|
411
|
-
return this._draggable.value;
|
|
412
|
-
}
|
|
409
|
+
protected _valSideEffectBinder: ValSideEffectBinder;
|
|
413
410
|
|
|
414
|
-
public
|
|
415
|
-
this._draggable.setValue(draggable, skipUpdate);
|
|
416
|
-
return this;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
protected _fence: Val<boolean, boolean>;
|
|
420
|
-
|
|
421
|
-
/** Restrict box to always be within the containing area. */
|
|
422
|
-
public get fence(): boolean {
|
|
423
|
-
return this._fence.value;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
public setFence(fence: boolean, skipUpdate = false): this {
|
|
427
|
-
this._fence.setValue(fence, skipUpdate);
|
|
428
|
-
return this;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
protected _fixRatio: Val<boolean, boolean>;
|
|
432
|
-
|
|
433
|
-
/** Fixed width/height ratio for box window. */
|
|
434
|
-
public get fixRatio(): boolean {
|
|
435
|
-
return this._fixRatio.value;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
public setFixRatio(fixRatio: boolean, skipUpdate = false): this {
|
|
439
|
-
this._fixRatio.setValue(fixRatio, skipUpdate);
|
|
440
|
-
return this;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
protected _focus: Val<boolean, boolean>;
|
|
444
|
-
|
|
445
|
-
public get focus(): boolean {
|
|
446
|
-
return this._focus.value;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
public setFocus(focus: boolean, skipUpdate = false): this {
|
|
450
|
-
this._focus.setValue(focus, skipUpdate);
|
|
451
|
-
return this;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
protected _zIndex: Val<number, boolean>;
|
|
455
|
-
|
|
456
|
-
public get zIndex(): number {
|
|
457
|
-
return this._zIndex.value;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
public setZIndex(zIndex: number, skipUpdate = false): this {
|
|
461
|
-
this._zIndex.setValue(zIndex, skipUpdate);
|
|
462
|
-
return this;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
protected _minimized: Val<boolean, boolean>;
|
|
466
|
-
|
|
467
|
-
public get minimized(): boolean {
|
|
468
|
-
return this._minimized.value;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
public setMinimized(minimized: boolean, skipUpdate = false): this {
|
|
472
|
-
this._minimized.setValue(minimized, skipUpdate);
|
|
473
|
-
return this;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
protected _maximized: Val<boolean, boolean>;
|
|
477
|
-
|
|
478
|
-
public get maximized(): boolean {
|
|
479
|
-
return this._maximized.value;
|
|
480
|
-
}
|
|
411
|
+
public titleBar: TeleTitleBar;
|
|
481
412
|
|
|
482
|
-
public
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
413
|
+
public _minSize$: Val<TeleBoxSize, boolean>;
|
|
414
|
+
public _size$: Val<TeleBoxSize, boolean>;
|
|
415
|
+
public _intrinsicSize$: Val<TeleBoxSize, boolean>;
|
|
416
|
+
public _visualSize$: Val<TeleBoxSize, boolean>;
|
|
417
|
+
public _coord$: Val<TeleBoxCoord, boolean>;
|
|
418
|
+
public _intrinsicCoord$: Val<TeleBoxCoord, boolean>;
|
|
486
419
|
|
|
487
|
-
|
|
420
|
+
public _state$: Val<TeleBoxState, boolean>;
|
|
488
421
|
|
|
489
|
-
/** Is box maximized. Default false. */
|
|
490
422
|
public get state(): TeleBoxState {
|
|
491
|
-
return this._state
|
|
423
|
+
return this._state$.value;
|
|
492
424
|
}
|
|
493
425
|
|
|
494
426
|
/** @deprecated use setMaximized and setMinimized instead */
|
|
@@ -513,21 +445,14 @@ export class TeleBox {
|
|
|
513
445
|
return this;
|
|
514
446
|
}
|
|
515
447
|
|
|
516
|
-
protected _minSize: Val<TeleBoxSize, boolean>;
|
|
517
|
-
|
|
518
448
|
/** Minimum box width relative to container element. 0~1. Default 0. */
|
|
519
449
|
public get minWidth(): number {
|
|
520
|
-
return this._minSize
|
|
450
|
+
return this._minSize$.value.width;
|
|
521
451
|
}
|
|
522
452
|
|
|
523
453
|
/** Minimum box height relative to container element. 0~1. Default 0. */
|
|
524
454
|
public get minHeight(): number {
|
|
525
|
-
return this._minSize
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
public setMinSize(size: TeleBoxSize, skipUpdate = false): this {
|
|
529
|
-
this._minSize.setValue(size, skipUpdate);
|
|
530
|
-
return this;
|
|
455
|
+
return this._minSize$.value.height;
|
|
531
456
|
}
|
|
532
457
|
|
|
533
458
|
/**
|
|
@@ -535,7 +460,7 @@ export class TeleBox {
|
|
|
535
460
|
* @returns this
|
|
536
461
|
*/
|
|
537
462
|
public setMinWidth(minWidth: number, skipUpdate = false): this {
|
|
538
|
-
this._minSize
|
|
463
|
+
this._minSize$.setValue(
|
|
539
464
|
{ width: minWidth, height: this.minHeight },
|
|
540
465
|
skipUpdate
|
|
541
466
|
);
|
|
@@ -547,28 +472,21 @@ export class TeleBox {
|
|
|
547
472
|
* @returns this
|
|
548
473
|
*/
|
|
549
474
|
public setMinHeight(minHeight: number, skipUpdate = false): this {
|
|
550
|
-
this._minSize
|
|
475
|
+
this._minSize$.setValue(
|
|
551
476
|
{ width: this.minWidth, height: minHeight },
|
|
552
477
|
skipUpdate
|
|
553
478
|
);
|
|
554
479
|
return this;
|
|
555
480
|
}
|
|
556
481
|
|
|
557
|
-
protected _intrinsicSize: Val<TeleBoxSize, boolean>;
|
|
558
|
-
|
|
559
482
|
/** Intrinsic box width relative to container element(without counting the effect of maximization or minimization). 0~1. Default 0.5. */
|
|
560
483
|
public get intrinsicWidth(): number {
|
|
561
|
-
return this._intrinsicSize
|
|
484
|
+
return this._intrinsicSize$.value.width;
|
|
562
485
|
}
|
|
563
486
|
|
|
564
487
|
/** Intrinsic box height relative to container element(without counting the effect of maximization or minimization). 0~1. Default 0.5. */
|
|
565
488
|
public get intrinsicHeight(): number {
|
|
566
|
-
return this._intrinsicSize
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
public setIntrinsicSize(size: TeleBoxSize, skipUpdate = false): this {
|
|
570
|
-
this._intrinsicSize.setValue(size, skipUpdate);
|
|
571
|
-
return this;
|
|
489
|
+
return this._intrinsicSize$.value.height;
|
|
572
490
|
}
|
|
573
491
|
|
|
574
492
|
/**
|
|
@@ -579,20 +497,18 @@ export class TeleBox {
|
|
|
579
497
|
* @returns this
|
|
580
498
|
*/
|
|
581
499
|
public resize(width: number, height: number, skipUpdate = false): this {
|
|
582
|
-
this._intrinsicSize
|
|
500
|
+
this._intrinsicSize$.setValue({ width, height }, skipUpdate);
|
|
583
501
|
return this;
|
|
584
502
|
}
|
|
585
503
|
|
|
586
|
-
protected _size: Val<TeleBoxSize, boolean>;
|
|
587
|
-
|
|
588
504
|
/** Box width relative to container element. 0~1. Default 0.5. */
|
|
589
505
|
public get width(): number {
|
|
590
|
-
return this._size
|
|
506
|
+
return this._size$.value.width;
|
|
591
507
|
}
|
|
592
508
|
|
|
593
509
|
/** Box height relative to container element. 0~1. Default 0.5. */
|
|
594
510
|
public get height(): number {
|
|
595
|
-
return this._size
|
|
511
|
+
return this._size$.value.height;
|
|
596
512
|
}
|
|
597
513
|
|
|
598
514
|
/** Box width in pixels. */
|
|
@@ -605,33 +521,24 @@ export class TeleBox {
|
|
|
605
521
|
return this.height * this.containerRect.height;
|
|
606
522
|
}
|
|
607
523
|
|
|
608
|
-
protected _visualSize: Val<TeleBoxSize, boolean>;
|
|
609
|
-
|
|
610
524
|
/** Actual rendered box width relative to container element. 0~1. Default 0.5. */
|
|
611
525
|
public get visualWidth(): number {
|
|
612
|
-
return this._visualSize
|
|
526
|
+
return this._visualSize$.value.width;
|
|
613
527
|
}
|
|
614
528
|
|
|
615
529
|
/** Actual rendered box height relative to container element. 0~1. Default 0.5. */
|
|
616
530
|
public get visualHeight(): number {
|
|
617
|
-
return this._visualSize
|
|
531
|
+
return this._visualSize$.value.height;
|
|
618
532
|
}
|
|
619
533
|
|
|
620
|
-
protected _intrinsicCoord: Val<TeleBoxCoord, boolean>;
|
|
621
|
-
|
|
622
534
|
/** Intrinsic box x position relative to container element(without counting the effect of maximization or minimization). 0~1. Default 0.1. */
|
|
623
535
|
public get intrinsicX(): number {
|
|
624
|
-
return this._intrinsicCoord
|
|
536
|
+
return this._intrinsicCoord$.value.x;
|
|
625
537
|
}
|
|
626
538
|
|
|
627
539
|
/** Intrinsic box y position relative to container element(without counting the effect of maximization or minimization). 0~1. Default 0.1. */
|
|
628
540
|
public get intrinsicY(): number {
|
|
629
|
-
return this._intrinsicCoord
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
public setIntrinsicCoord(coord: TeleBoxCoord, skipUpdate = false): this {
|
|
633
|
-
this._intrinsicCoord.setValue(coord, skipUpdate);
|
|
634
|
-
return this;
|
|
541
|
+
return this._intrinsicCoord$.value.y;
|
|
635
542
|
}
|
|
636
543
|
|
|
637
544
|
/**
|
|
@@ -642,20 +549,18 @@ export class TeleBox {
|
|
|
642
549
|
* @returns this
|
|
643
550
|
*/
|
|
644
551
|
public move(x: number, y: number, skipUpdate = false): this {
|
|
645
|
-
this._intrinsicCoord
|
|
552
|
+
this._intrinsicCoord$.setValue({ x, y }, skipUpdate);
|
|
646
553
|
return this;
|
|
647
554
|
}
|
|
648
555
|
|
|
649
|
-
protected _coord: Val<TeleBoxCoord, boolean>;
|
|
650
|
-
|
|
651
556
|
/** Box x position relative to container element. 0~1. Default 0.1. */
|
|
652
557
|
public get x(): number {
|
|
653
|
-
return this._coord
|
|
558
|
+
return this._coord$.value.x;
|
|
654
559
|
}
|
|
655
560
|
|
|
656
561
|
/** Box y position relative to container element. 0~1. Default 0.1. */
|
|
657
562
|
public get y(): number {
|
|
658
|
-
return this._coord
|
|
563
|
+
return this._coord$.value.y;
|
|
659
564
|
}
|
|
660
565
|
|
|
661
566
|
/**
|
|
@@ -690,14 +595,14 @@ export class TeleBox {
|
|
|
690
595
|
}
|
|
691
596
|
}
|
|
692
597
|
|
|
693
|
-
this.
|
|
598
|
+
this._intrinsicCoord$.setValue(
|
|
694
599
|
{
|
|
695
600
|
x: width >= this.minWidth ? x : this.intrinsicX,
|
|
696
601
|
y: height >= this.minHeight ? y : this.intrinsicY,
|
|
697
602
|
},
|
|
698
603
|
skipUpdate
|
|
699
604
|
);
|
|
700
|
-
this.
|
|
605
|
+
this._intrinsicSize$.setValue(
|
|
701
606
|
{
|
|
702
607
|
width: clamp(width, this.minWidth, 1),
|
|
703
608
|
height: clamp(height, this.minHeight, 1),
|
|
@@ -708,12 +613,6 @@ export class TeleBox {
|
|
|
708
613
|
return this;
|
|
709
614
|
}
|
|
710
615
|
|
|
711
|
-
protected _$userContent: Val<HTMLElement | undefined>;
|
|
712
|
-
|
|
713
|
-
public get $userContent(): HTMLElement | undefined {
|
|
714
|
-
return this._$userContent.value;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
616
|
/**
|
|
718
617
|
* Mount box to a container element.
|
|
719
618
|
*/
|
|
@@ -736,7 +635,7 @@ export class TeleBox {
|
|
|
736
635
|
* Mount dom to box content.
|
|
737
636
|
*/
|
|
738
637
|
public mountContent(content: HTMLElement): this {
|
|
739
|
-
this.
|
|
638
|
+
this.set$userContent(content);
|
|
740
639
|
return this;
|
|
741
640
|
}
|
|
742
641
|
|
|
@@ -744,21 +643,15 @@ export class TeleBox {
|
|
|
744
643
|
* Unmount content from the box.
|
|
745
644
|
*/
|
|
746
645
|
public unmountContent(): this {
|
|
747
|
-
this.
|
|
646
|
+
this.set$userContent(undefined);
|
|
748
647
|
return this;
|
|
749
648
|
}
|
|
750
649
|
|
|
751
|
-
protected _$userFooter: Val<HTMLElement | undefined>;
|
|
752
|
-
|
|
753
|
-
public get $userFooter(): HTMLElement | undefined {
|
|
754
|
-
return this._$userFooter.value;
|
|
755
|
-
}
|
|
756
|
-
|
|
757
650
|
/**
|
|
758
651
|
* Mount dom to box Footer.
|
|
759
652
|
*/
|
|
760
653
|
public mountFooter(footer: HTMLElement): this {
|
|
761
|
-
this.
|
|
654
|
+
this.set$userFooter(footer);
|
|
762
655
|
return this;
|
|
763
656
|
}
|
|
764
657
|
|
|
@@ -766,14 +659,12 @@ export class TeleBox {
|
|
|
766
659
|
* Unmount Footer from the box.
|
|
767
660
|
*/
|
|
768
661
|
public unmountFooter(): this {
|
|
769
|
-
this.
|
|
662
|
+
this.set$userFooter(undefined);
|
|
770
663
|
return this;
|
|
771
664
|
}
|
|
772
665
|
|
|
773
|
-
protected _$userStyles: Val<HTMLStyleElement | undefined>;
|
|
774
|
-
|
|
775
666
|
public getUserStyles(): HTMLStyleElement | undefined {
|
|
776
|
-
return this
|
|
667
|
+
return this.$userStyles;
|
|
777
668
|
}
|
|
778
669
|
|
|
779
670
|
public mountStyles(styles: string | HTMLStyleElement): this {
|
|
@@ -784,12 +675,12 @@ export class TeleBox {
|
|
|
784
675
|
} else {
|
|
785
676
|
$styles = styles;
|
|
786
677
|
}
|
|
787
|
-
this.
|
|
678
|
+
this.set$userStyles($styles);
|
|
788
679
|
return this;
|
|
789
680
|
}
|
|
790
681
|
|
|
791
682
|
public unmountStyles(): this {
|
|
792
|
-
this.
|
|
683
|
+
this.set$userStyles(undefined);
|
|
793
684
|
return this;
|
|
794
685
|
}
|
|
795
686
|
|
|
@@ -837,17 +728,17 @@ export class TeleBox {
|
|
|
837
728
|
});
|
|
838
729
|
};
|
|
839
730
|
|
|
840
|
-
bindClassName(this.$box, this._readonly
|
|
841
|
-
bindClassName(this.$box, this._draggable
|
|
842
|
-
bindClassName(this.$box, this._resizable
|
|
843
|
-
bindClassName(this.$box, this._focus
|
|
731
|
+
bindClassName(this.$box, this._readonly$, "readonly");
|
|
732
|
+
bindClassName(this.$box, this._draggable$, "no-drag", isFalsy);
|
|
733
|
+
bindClassName(this.$box, this._resizable$, "no-resize", isFalsy);
|
|
734
|
+
bindClassName(this.$box, this._focus$, "blur", isFalsy);
|
|
844
735
|
|
|
845
736
|
this._renderSideEffect.add(() => {
|
|
846
737
|
const minimizedClassName = this.wrapClassName("minimized");
|
|
847
738
|
const maximizedClassName = this.wrapClassName("maximized");
|
|
848
739
|
const MAXIMIZED_TIMER_ID = "box-maximized-timer";
|
|
849
740
|
|
|
850
|
-
return this._state
|
|
741
|
+
return this._state$.subscribe((state) => {
|
|
851
742
|
this.$box.classList.toggle(
|
|
852
743
|
minimizedClassName,
|
|
853
744
|
state === TELE_BOX_STATE.Minimized
|
|
@@ -873,13 +764,13 @@ export class TeleBox {
|
|
|
873
764
|
});
|
|
874
765
|
|
|
875
766
|
this._renderSideEffect.add(() =>
|
|
876
|
-
this._visible
|
|
767
|
+
this._visible$.subscribe((visible) => {
|
|
877
768
|
this.$box.style.display = visible ? "block" : "none";
|
|
878
769
|
})
|
|
879
770
|
);
|
|
880
771
|
|
|
881
772
|
this._renderSideEffect.add(() =>
|
|
882
|
-
this._zIndex
|
|
773
|
+
this._zIndex$.subscribe((zIndex) => {
|
|
883
774
|
this.$box.style.zIndex = String(zIndex);
|
|
884
775
|
})
|
|
885
776
|
);
|
|
@@ -900,14 +791,14 @@ export class TeleBox {
|
|
|
900
791
|
translateY - 10
|
|
901
792
|
}px)`;
|
|
902
793
|
|
|
903
|
-
this.
|
|
904
|
-
|
|
794
|
+
this._valSideEffectBinder
|
|
795
|
+
.combine(
|
|
905
796
|
[
|
|
906
|
-
this._coord
|
|
907
|
-
this._size
|
|
908
|
-
this._minimized
|
|
909
|
-
this._containerRect
|
|
910
|
-
this._collectorRect
|
|
797
|
+
this._coord$,
|
|
798
|
+
this._size$,
|
|
799
|
+
this._minimized$,
|
|
800
|
+
this._containerRect$,
|
|
801
|
+
this._collectorRect$,
|
|
911
802
|
],
|
|
912
803
|
([coord, size, minimized, containerRect, collectorRect]) => {
|
|
913
804
|
const absoluteWidth = size.width * containerRect.width;
|
|
@@ -928,17 +819,11 @@ export class TeleBox {
|
|
|
928
819
|
};
|
|
929
820
|
},
|
|
930
821
|
shallowequal
|
|
931
|
-
)
|
|
932
|
-
|
|
933
|
-
combined.subscribe((styles) => {
|
|
822
|
+
)
|
|
823
|
+
.subscribe((styles) => {
|
|
934
824
|
boxStyler.set(styles);
|
|
935
825
|
});
|
|
936
826
|
|
|
937
|
-
return () => {
|
|
938
|
-
combined.destroy();
|
|
939
|
-
};
|
|
940
|
-
});
|
|
941
|
-
|
|
942
827
|
boxStyler.set({ x: translateX, y: translateY });
|
|
943
828
|
|
|
944
829
|
const $boxMain = document.createElement("div");
|
|
@@ -959,7 +844,7 @@ export class TeleBox {
|
|
|
959
844
|
|
|
960
845
|
this._renderSideEffect.add(() => {
|
|
961
846
|
let last$userStyles: HTMLStyleElement | undefined;
|
|
962
|
-
return this._$userStyles
|
|
847
|
+
return this._$userStyles$.subscribe(($userStyles) => {
|
|
963
848
|
if (last$userStyles) {
|
|
964
849
|
last$userStyles.remove();
|
|
965
850
|
}
|
|
@@ -972,7 +857,7 @@ export class TeleBox {
|
|
|
972
857
|
|
|
973
858
|
this._renderSideEffect.add(() => {
|
|
974
859
|
let last$userContent: HTMLElement | undefined;
|
|
975
|
-
return this._$userContent
|
|
860
|
+
return this._$userContent$.subscribe(($userContent) => {
|
|
976
861
|
if (last$userContent) {
|
|
977
862
|
last$userContent.remove();
|
|
978
863
|
}
|
|
@@ -991,13 +876,13 @@ export class TeleBox {
|
|
|
991
876
|
|
|
992
877
|
this._renderSideEffect.add(() => {
|
|
993
878
|
let last$userFooter: HTMLElement | undefined;
|
|
994
|
-
return this._$userFooter
|
|
879
|
+
return this._$userFooter$.subscribe(($userFooter) => {
|
|
995
880
|
if (last$userFooter) {
|
|
996
881
|
last$userFooter.remove();
|
|
997
882
|
}
|
|
998
883
|
last$userFooter = $userFooter;
|
|
999
884
|
if ($userFooter) {
|
|
1000
|
-
$
|
|
885
|
+
$footer.appendChild($userFooter);
|
|
1001
886
|
}
|
|
1002
887
|
});
|
|
1003
888
|
});
|
|
@@ -1141,7 +1026,7 @@ export class TeleBox {
|
|
|
1141
1026
|
break;
|
|
1142
1027
|
}
|
|
1143
1028
|
default: {
|
|
1144
|
-
if (this.
|
|
1029
|
+
if (this.fence) {
|
|
1145
1030
|
this.move(
|
|
1146
1031
|
clamp(trackStartX + offsetX, 0, 1 - this.width),
|
|
1147
1032
|
clamp(trackStartY + offsetY, 0, 1 - this.height)
|
|
@@ -1285,12 +1170,6 @@ export class TeleBox {
|
|
|
1285
1170
|
this._renderSideEffect.flushAll();
|
|
1286
1171
|
this.events.removeAllListeners();
|
|
1287
1172
|
this._delegateEvents.removeAllListeners();
|
|
1288
|
-
Object.keys(this).forEach((key) => {
|
|
1289
|
-
const value = this[key as keyof this];
|
|
1290
|
-
if (value instanceof Val) {
|
|
1291
|
-
value.destroy();
|
|
1292
|
-
}
|
|
1293
|
-
});
|
|
1294
1173
|
}
|
|
1295
1174
|
|
|
1296
1175
|
/**
|