@netless/telebox-insider 0.2.3 → 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/index.d.ts +40 -69
- package/dist/TeleBoxManager/index.d.ts +14 -23
- 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/index.ts +184 -316
- package/src/TeleBoxManager/index.ts +89 -126
- 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,22 +146,22 @@ export class TeleBox {
|
|
|
109
146
|
}
|
|
110
147
|
});
|
|
111
148
|
|
|
112
|
-
|
|
113
|
-
|
|
149
|
+
const minimized$ = createVal(minimized);
|
|
150
|
+
minimized$.reaction((minimized, _, skipUpdate) => {
|
|
114
151
|
if (!skipUpdate) {
|
|
115
152
|
this.events.emit(TELE_BOX_EVENT.Minimized, minimized);
|
|
116
153
|
}
|
|
117
154
|
});
|
|
118
155
|
|
|
119
|
-
|
|
120
|
-
|
|
156
|
+
const maximized$ = createVal(maximized);
|
|
157
|
+
maximized$.reaction((maximized, _, skipUpdate) => {
|
|
121
158
|
if (!skipUpdate) {
|
|
122
159
|
this.events.emit(TELE_BOX_EVENT.Maximized, maximized);
|
|
123
160
|
}
|
|
124
161
|
});
|
|
125
162
|
|
|
126
|
-
|
|
127
|
-
[
|
|
163
|
+
const state$ = combine(
|
|
164
|
+
[minimized$, maximized$],
|
|
128
165
|
([minimized, maximized]): TeleBoxState =>
|
|
129
166
|
minimized
|
|
130
167
|
? TELE_BOX_STATE.Minimized
|
|
@@ -132,13 +169,13 @@ export class TeleBox {
|
|
|
132
169
|
? TELE_BOX_STATE.Maximized
|
|
133
170
|
: TELE_BOX_STATE.Normal
|
|
134
171
|
);
|
|
135
|
-
|
|
172
|
+
state$.reaction((state, _, skipUpdate) => {
|
|
136
173
|
if (!skipUpdate) {
|
|
137
174
|
this.events.emit(TELE_BOX_EVENT.State, state);
|
|
138
175
|
}
|
|
139
176
|
});
|
|
140
177
|
|
|
141
|
-
|
|
178
|
+
const minSize$ = createVal(
|
|
142
179
|
{
|
|
143
180
|
width: clamp(minWidth, 0, 1),
|
|
144
181
|
height: clamp(minHeight, 0, 1),
|
|
@@ -146,15 +183,15 @@ export class TeleBox {
|
|
|
146
183
|
shallowequal
|
|
147
184
|
);
|
|
148
185
|
|
|
149
|
-
|
|
186
|
+
const intrinsicSize$ = createVal(
|
|
150
187
|
{
|
|
151
|
-
width: clamp(width,
|
|
152
|
-
height: clamp(height,
|
|
188
|
+
width: clamp(width, minSize$.value.width, 1),
|
|
189
|
+
height: clamp(height, minSize$.value.height, 1),
|
|
153
190
|
},
|
|
154
191
|
shallowequal
|
|
155
192
|
);
|
|
156
|
-
|
|
157
|
-
|
|
193
|
+
minSize$.reaction((minSize, _, skipUpdate) => {
|
|
194
|
+
intrinsicSize$.setValue(
|
|
158
195
|
{
|
|
159
196
|
width: clamp(width, minSize.width, 1),
|
|
160
197
|
height: clamp(height, minSize.height, 1),
|
|
@@ -162,14 +199,14 @@ export class TeleBox {
|
|
|
162
199
|
skipUpdate
|
|
163
200
|
);
|
|
164
201
|
});
|
|
165
|
-
|
|
202
|
+
intrinsicSize$.reaction((size, _, skipUpdate) => {
|
|
166
203
|
if (!skipUpdate) {
|
|
167
204
|
this.events.emit(TELE_BOX_EVENT.IntrinsicResize, size);
|
|
168
205
|
}
|
|
169
206
|
});
|
|
170
207
|
|
|
171
|
-
|
|
172
|
-
[
|
|
208
|
+
const size$ = combine(
|
|
209
|
+
[intrinsicSize$, maximized$],
|
|
173
210
|
([intrinsicSize, maximized]) => {
|
|
174
211
|
if (maximized) {
|
|
175
212
|
return { width: 1, height: 1 };
|
|
@@ -178,19 +215,14 @@ export class TeleBox {
|
|
|
178
215
|
},
|
|
179
216
|
shallowequal
|
|
180
217
|
);
|
|
181
|
-
|
|
218
|
+
size$.reaction((size, _, skipUpdate) => {
|
|
182
219
|
if (!skipUpdate) {
|
|
183
220
|
this.events.emit(TELE_BOX_EVENT.Resize, size);
|
|
184
221
|
}
|
|
185
222
|
});
|
|
186
223
|
|
|
187
|
-
|
|
188
|
-
[
|
|
189
|
-
this._size,
|
|
190
|
-
this._minimized,
|
|
191
|
-
this._containerRect,
|
|
192
|
-
this._collectorRect,
|
|
193
|
-
],
|
|
224
|
+
const visualSize$ = combine(
|
|
225
|
+
[size$, minimized$, containerRect$, collectorRect$],
|
|
194
226
|
([size, minimized, containerRect, collectorRect]) => {
|
|
195
227
|
if (minimized && collectorRect) {
|
|
196
228
|
return {
|
|
@@ -208,30 +240,30 @@ export class TeleBox {
|
|
|
208
240
|
},
|
|
209
241
|
shallowequal
|
|
210
242
|
);
|
|
211
|
-
|
|
243
|
+
visualSize$.reaction((size, _, skipUpdate) => {
|
|
212
244
|
if (!skipUpdate) {
|
|
213
245
|
this.events.emit(TELE_BOX_EVENT.VisualResize, size);
|
|
214
246
|
}
|
|
215
247
|
});
|
|
216
248
|
|
|
217
|
-
|
|
249
|
+
const intrinsicCoord$ = createVal(
|
|
218
250
|
{ x: clamp(x, 0, 1), y: clamp(y, 0, 1) },
|
|
219
251
|
shallowequal
|
|
220
252
|
);
|
|
221
|
-
|
|
253
|
+
intrinsicCoord$.reaction((coord, _, skipUpdate) => {
|
|
222
254
|
if (!skipUpdate) {
|
|
223
255
|
this.events.emit(TELE_BOX_EVENT.IntrinsicMove, coord);
|
|
224
256
|
}
|
|
225
257
|
});
|
|
226
258
|
|
|
227
|
-
|
|
259
|
+
const coord$ = combine(
|
|
228
260
|
[
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
261
|
+
intrinsicCoord$,
|
|
262
|
+
intrinsicSize$,
|
|
263
|
+
containerRect$,
|
|
264
|
+
collectorRect$,
|
|
265
|
+
minimized$,
|
|
266
|
+
maximized$,
|
|
235
267
|
],
|
|
236
268
|
([
|
|
237
269
|
intrinsicCoord,
|
|
@@ -272,7 +304,7 @@ export class TeleBox {
|
|
|
272
304
|
},
|
|
273
305
|
shallowequal
|
|
274
306
|
);
|
|
275
|
-
|
|
307
|
+
coord$.reaction((coord, _, skipUpdate) => {
|
|
276
308
|
if (!skipUpdate) {
|
|
277
309
|
this.events.emit(TELE_BOX_EVENT.Move, coord);
|
|
278
310
|
}
|
|
@@ -281,8 +313,8 @@ export class TeleBox {
|
|
|
281
313
|
this.titleBar =
|
|
282
314
|
titleBar ||
|
|
283
315
|
new DefaultTitleBar({
|
|
284
|
-
readonly:
|
|
285
|
-
title:
|
|
316
|
+
readonly: readonly$.value,
|
|
317
|
+
title: title$.value,
|
|
286
318
|
namespace: this.namespace,
|
|
287
319
|
onDragStart: (event) => this._handleTrackStart?.(event),
|
|
288
320
|
onEvent: (event): void => {
|
|
@@ -291,15 +323,15 @@ export class TeleBox {
|
|
|
291
323
|
} else {
|
|
292
324
|
switch (event.type) {
|
|
293
325
|
case TELE_BOX_DELEGATE_EVENT.Maximize: {
|
|
294
|
-
|
|
326
|
+
maximized$.setValue(!maximized$.value);
|
|
295
327
|
break;
|
|
296
328
|
}
|
|
297
329
|
case TELE_BOX_DELEGATE_EVENT.Minimize: {
|
|
298
|
-
|
|
330
|
+
minimized$.setValue(true);
|
|
299
331
|
break;
|
|
300
332
|
}
|
|
301
333
|
case TELE_BOX_DELEGATE_EVENT.Close: {
|
|
302
|
-
|
|
334
|
+
visible$.setValue(false);
|
|
303
335
|
break;
|
|
304
336
|
}
|
|
305
337
|
default: {
|
|
@@ -313,16 +345,51 @@ export class TeleBox {
|
|
|
313
345
|
}
|
|
314
346
|
},
|
|
315
347
|
});
|
|
316
|
-
|
|
348
|
+
readonly$.reaction((readonly) => {
|
|
317
349
|
this.titleBar.setReadonly(readonly);
|
|
318
350
|
});
|
|
319
351
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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$;
|
|
323
384
|
|
|
324
385
|
if (this.fixRatio) {
|
|
325
|
-
this.transform(
|
|
386
|
+
this.transform(
|
|
387
|
+
coord$.value.x,
|
|
388
|
+
coord$.value.y,
|
|
389
|
+
size$.value.width,
|
|
390
|
+
size$.value.height,
|
|
391
|
+
true
|
|
392
|
+
);
|
|
326
393
|
}
|
|
327
394
|
|
|
328
395
|
this.$box = this.render();
|
|
@@ -330,7 +397,7 @@ export class TeleBox {
|
|
|
330
397
|
|
|
331
398
|
public readonly id: string;
|
|
332
399
|
|
|
333
|
-
/**
|
|
400
|
+
/** ClassName Prefix. For CSS styling. Default "telebox" */
|
|
334
401
|
public readonly namespace: string;
|
|
335
402
|
|
|
336
403
|
public readonly events: TeleBoxEvents;
|
|
@@ -339,167 +406,21 @@ export class TeleBox {
|
|
|
339
406
|
|
|
340
407
|
protected _sideEffect: SideEffectManager;
|
|
341
408
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
protected _containerRect: Val<TeleBoxRect, boolean>;
|
|
345
|
-
|
|
346
|
-
public get containerRect(): TeleBoxRect {
|
|
347
|
-
return this._containerRect.value;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
public setContainerRect(rect: TeleBoxRect, skipUpdate = false): this {
|
|
351
|
-
this._containerRect.setValue(rect, skipUpdate);
|
|
352
|
-
return this;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
protected _collectorRect: Val<TeleBoxRect | undefined, boolean>;
|
|
356
|
-
|
|
357
|
-
public get collectorRect(): TeleBoxRect | undefined {
|
|
358
|
-
return this._collectorRect.value;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
public setCollectorRect(rect: TeleBoxRect, skipUpdate = false): this {
|
|
362
|
-
this._collectorRect.setValue(rect, skipUpdate);
|
|
363
|
-
return this;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
protected _title: Val<string, boolean>;
|
|
367
|
-
|
|
368
|
-
/** Box title. Default empty. */
|
|
369
|
-
public get title(): string {
|
|
370
|
-
return this._title.value;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Update box title.
|
|
375
|
-
* @param title new box title
|
|
376
|
-
* @returns this
|
|
377
|
-
*/
|
|
378
|
-
public setTitle(title: string): this {
|
|
379
|
-
this._title.setValue(title);
|
|
380
|
-
return this;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
protected _visible: Val<boolean, boolean>;
|
|
384
|
-
|
|
385
|
-
public get visible(): boolean {
|
|
386
|
-
return this._visible.value;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
public setVisible(visible: boolean, skipUpdate = false): this {
|
|
390
|
-
this._visible.setValue(visible, skipUpdate);
|
|
391
|
-
return this;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
protected _readonly: Val<boolean, boolean>;
|
|
395
|
-
|
|
396
|
-
/** Is box readonly */
|
|
397
|
-
public get readonly(): boolean {
|
|
398
|
-
return this._readonly.value;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
public setReadonly(readonly: boolean, skipUpdate = false): this {
|
|
402
|
-
this._readonly.setValue(readonly, skipUpdate);
|
|
403
|
-
return this;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
protected _resizable: Val<boolean, boolean>;
|
|
407
|
-
|
|
408
|
-
/** Able to resize box window */
|
|
409
|
-
public get resizable(): boolean {
|
|
410
|
-
return this._resizable.value;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
public setResizable(resizable: boolean, skipUpdate = false): this {
|
|
414
|
-
this._resizable.setValue(resizable, skipUpdate);
|
|
415
|
-
return this;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
protected _draggable: Val<boolean, boolean>;
|
|
419
|
-
|
|
420
|
-
/** Able to drag box window */
|
|
421
|
-
public get draggable(): boolean {
|
|
422
|
-
return this._draggable.value;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
public setDraggable(draggable: boolean, skipUpdate = false): this {
|
|
426
|
-
this._draggable.setValue(draggable, skipUpdate);
|
|
427
|
-
return this;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
protected _fence: Val<boolean, boolean>;
|
|
431
|
-
|
|
432
|
-
/** Restrict box to always be within the containing area. */
|
|
433
|
-
public get fence(): boolean {
|
|
434
|
-
return this._fence.value;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
public setFence(fence: boolean, skipUpdate = false): this {
|
|
438
|
-
this._fence.setValue(fence, skipUpdate);
|
|
439
|
-
return this;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
protected _fixRatio: Val<boolean, boolean>;
|
|
443
|
-
|
|
444
|
-
/** Fixed width/height ratio for box window. */
|
|
445
|
-
public get fixRatio(): boolean {
|
|
446
|
-
return this._fixRatio.value;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
public setFixRatio(fixRatio: boolean, skipUpdate = false): this {
|
|
450
|
-
this._fixRatio.setValue(fixRatio, skipUpdate);
|
|
451
|
-
return this;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
protected _focus: Val<boolean, boolean>;
|
|
455
|
-
|
|
456
|
-
public get focus(): boolean {
|
|
457
|
-
return this._focus.value;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
public setFocus(focus: boolean, skipUpdate = false): this {
|
|
461
|
-
this._focus.setValue(focus, skipUpdate);
|
|
462
|
-
return this;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
protected _zIndex: Val<number, boolean>;
|
|
466
|
-
|
|
467
|
-
public get zIndex(): number {
|
|
468
|
-
return this._zIndex.value;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
public setZIndex(zIndex: number, skipUpdate = false): this {
|
|
472
|
-
this._zIndex.setValue(zIndex, skipUpdate);
|
|
473
|
-
return this;
|
|
474
|
-
}
|
|
409
|
+
protected _valSideEffectBinder: ValSideEffectBinder;
|
|
475
410
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
public get minimized(): boolean {
|
|
479
|
-
return this._minimized.value;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
public setMinimized(minimized: boolean, skipUpdate = false): this {
|
|
483
|
-
this._minimized.setValue(minimized, skipUpdate);
|
|
484
|
-
return this;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
protected _maximized: Val<boolean, boolean>;
|
|
488
|
-
|
|
489
|
-
public get maximized(): boolean {
|
|
490
|
-
return this._maximized.value;
|
|
491
|
-
}
|
|
411
|
+
public titleBar: TeleTitleBar;
|
|
492
412
|
|
|
493
|
-
public
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
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>;
|
|
497
419
|
|
|
498
|
-
|
|
420
|
+
public _state$: Val<TeleBoxState, boolean>;
|
|
499
421
|
|
|
500
|
-
/** Is box maximized. Default false. */
|
|
501
422
|
public get state(): TeleBoxState {
|
|
502
|
-
return this._state
|
|
423
|
+
return this._state$.value;
|
|
503
424
|
}
|
|
504
425
|
|
|
505
426
|
/** @deprecated use setMaximized and setMinimized instead */
|
|
@@ -524,21 +445,14 @@ export class TeleBox {
|
|
|
524
445
|
return this;
|
|
525
446
|
}
|
|
526
447
|
|
|
527
|
-
protected _minSize: Val<TeleBoxSize, boolean>;
|
|
528
|
-
|
|
529
448
|
/** Minimum box width relative to container element. 0~1. Default 0. */
|
|
530
449
|
public get minWidth(): number {
|
|
531
|
-
return this._minSize
|
|
450
|
+
return this._minSize$.value.width;
|
|
532
451
|
}
|
|
533
452
|
|
|
534
453
|
/** Minimum box height relative to container element. 0~1. Default 0. */
|
|
535
454
|
public get minHeight(): number {
|
|
536
|
-
return this._minSize
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
public setMinSize(size: TeleBoxSize, skipUpdate = false): this {
|
|
540
|
-
this._minSize.setValue(size, skipUpdate);
|
|
541
|
-
return this;
|
|
455
|
+
return this._minSize$.value.height;
|
|
542
456
|
}
|
|
543
457
|
|
|
544
458
|
/**
|
|
@@ -546,7 +460,7 @@ export class TeleBox {
|
|
|
546
460
|
* @returns this
|
|
547
461
|
*/
|
|
548
462
|
public setMinWidth(minWidth: number, skipUpdate = false): this {
|
|
549
|
-
this._minSize
|
|
463
|
+
this._minSize$.setValue(
|
|
550
464
|
{ width: minWidth, height: this.minHeight },
|
|
551
465
|
skipUpdate
|
|
552
466
|
);
|
|
@@ -558,28 +472,21 @@ export class TeleBox {
|
|
|
558
472
|
* @returns this
|
|
559
473
|
*/
|
|
560
474
|
public setMinHeight(minHeight: number, skipUpdate = false): this {
|
|
561
|
-
this._minSize
|
|
475
|
+
this._minSize$.setValue(
|
|
562
476
|
{ width: this.minWidth, height: minHeight },
|
|
563
477
|
skipUpdate
|
|
564
478
|
);
|
|
565
479
|
return this;
|
|
566
480
|
}
|
|
567
481
|
|
|
568
|
-
protected _intrinsicSize: Val<TeleBoxSize, boolean>;
|
|
569
|
-
|
|
570
482
|
/** Intrinsic box width relative to container element(without counting the effect of maximization or minimization). 0~1. Default 0.5. */
|
|
571
483
|
public get intrinsicWidth(): number {
|
|
572
|
-
return this._intrinsicSize
|
|
484
|
+
return this._intrinsicSize$.value.width;
|
|
573
485
|
}
|
|
574
486
|
|
|
575
487
|
/** Intrinsic box height relative to container element(without counting the effect of maximization or minimization). 0~1. Default 0.5. */
|
|
576
488
|
public get intrinsicHeight(): number {
|
|
577
|
-
return this._intrinsicSize
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
public setIntrinsicSize(size: TeleBoxSize, skipUpdate = false): this {
|
|
581
|
-
this._intrinsicSize.setValue(size, skipUpdate);
|
|
582
|
-
return this;
|
|
489
|
+
return this._intrinsicSize$.value.height;
|
|
583
490
|
}
|
|
584
491
|
|
|
585
492
|
/**
|
|
@@ -590,20 +497,18 @@ export class TeleBox {
|
|
|
590
497
|
* @returns this
|
|
591
498
|
*/
|
|
592
499
|
public resize(width: number, height: number, skipUpdate = false): this {
|
|
593
|
-
this._intrinsicSize
|
|
500
|
+
this._intrinsicSize$.setValue({ width, height }, skipUpdate);
|
|
594
501
|
return this;
|
|
595
502
|
}
|
|
596
503
|
|
|
597
|
-
protected _size: Val<TeleBoxSize, boolean>;
|
|
598
|
-
|
|
599
504
|
/** Box width relative to container element. 0~1. Default 0.5. */
|
|
600
505
|
public get width(): number {
|
|
601
|
-
return this._size
|
|
506
|
+
return this._size$.value.width;
|
|
602
507
|
}
|
|
603
508
|
|
|
604
509
|
/** Box height relative to container element. 0~1. Default 0.5. */
|
|
605
510
|
public get height(): number {
|
|
606
|
-
return this._size
|
|
511
|
+
return this._size$.value.height;
|
|
607
512
|
}
|
|
608
513
|
|
|
609
514
|
/** Box width in pixels. */
|
|
@@ -616,33 +521,24 @@ export class TeleBox {
|
|
|
616
521
|
return this.height * this.containerRect.height;
|
|
617
522
|
}
|
|
618
523
|
|
|
619
|
-
protected _visualSize: Val<TeleBoxSize, boolean>;
|
|
620
|
-
|
|
621
524
|
/** Actual rendered box width relative to container element. 0~1. Default 0.5. */
|
|
622
525
|
public get visualWidth(): number {
|
|
623
|
-
return this._visualSize
|
|
526
|
+
return this._visualSize$.value.width;
|
|
624
527
|
}
|
|
625
528
|
|
|
626
529
|
/** Actual rendered box height relative to container element. 0~1. Default 0.5. */
|
|
627
530
|
public get visualHeight(): number {
|
|
628
|
-
return this._visualSize
|
|
531
|
+
return this._visualSize$.value.height;
|
|
629
532
|
}
|
|
630
533
|
|
|
631
|
-
protected _intrinsicCoord: Val<TeleBoxCoord, boolean>;
|
|
632
|
-
|
|
633
534
|
/** Intrinsic box x position relative to container element(without counting the effect of maximization or minimization). 0~1. Default 0.1. */
|
|
634
535
|
public get intrinsicX(): number {
|
|
635
|
-
return this._intrinsicCoord
|
|
536
|
+
return this._intrinsicCoord$.value.x;
|
|
636
537
|
}
|
|
637
538
|
|
|
638
539
|
/** Intrinsic box y position relative to container element(without counting the effect of maximization or minimization). 0~1. Default 0.1. */
|
|
639
540
|
public get intrinsicY(): number {
|
|
640
|
-
return this._intrinsicCoord
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
public setIntrinsicCoord(coord: TeleBoxCoord, skipUpdate = false): this {
|
|
644
|
-
this._intrinsicCoord.setValue(coord, skipUpdate);
|
|
645
|
-
return this;
|
|
541
|
+
return this._intrinsicCoord$.value.y;
|
|
646
542
|
}
|
|
647
543
|
|
|
648
544
|
/**
|
|
@@ -653,20 +549,18 @@ export class TeleBox {
|
|
|
653
549
|
* @returns this
|
|
654
550
|
*/
|
|
655
551
|
public move(x: number, y: number, skipUpdate = false): this {
|
|
656
|
-
this._intrinsicCoord
|
|
552
|
+
this._intrinsicCoord$.setValue({ x, y }, skipUpdate);
|
|
657
553
|
return this;
|
|
658
554
|
}
|
|
659
555
|
|
|
660
|
-
protected _coord: Val<TeleBoxCoord, boolean>;
|
|
661
|
-
|
|
662
556
|
/** Box x position relative to container element. 0~1. Default 0.1. */
|
|
663
557
|
public get x(): number {
|
|
664
|
-
return this._coord
|
|
558
|
+
return this._coord$.value.x;
|
|
665
559
|
}
|
|
666
560
|
|
|
667
561
|
/** Box y position relative to container element. 0~1. Default 0.1. */
|
|
668
562
|
public get y(): number {
|
|
669
|
-
return this._coord
|
|
563
|
+
return this._coord$.value.y;
|
|
670
564
|
}
|
|
671
565
|
|
|
672
566
|
/**
|
|
@@ -701,14 +595,14 @@ export class TeleBox {
|
|
|
701
595
|
}
|
|
702
596
|
}
|
|
703
597
|
|
|
704
|
-
this.
|
|
598
|
+
this._intrinsicCoord$.setValue(
|
|
705
599
|
{
|
|
706
600
|
x: width >= this.minWidth ? x : this.intrinsicX,
|
|
707
601
|
y: height >= this.minHeight ? y : this.intrinsicY,
|
|
708
602
|
},
|
|
709
603
|
skipUpdate
|
|
710
604
|
);
|
|
711
|
-
this.
|
|
605
|
+
this._intrinsicSize$.setValue(
|
|
712
606
|
{
|
|
713
607
|
width: clamp(width, this.minWidth, 1),
|
|
714
608
|
height: clamp(height, this.minHeight, 1),
|
|
@@ -719,12 +613,6 @@ export class TeleBox {
|
|
|
719
613
|
return this;
|
|
720
614
|
}
|
|
721
615
|
|
|
722
|
-
protected _$userContent: Val<HTMLElement | undefined>;
|
|
723
|
-
|
|
724
|
-
public get $userContent(): HTMLElement | undefined {
|
|
725
|
-
return this._$userContent.value;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
616
|
/**
|
|
729
617
|
* Mount box to a container element.
|
|
730
618
|
*/
|
|
@@ -747,7 +635,7 @@ export class TeleBox {
|
|
|
747
635
|
* Mount dom to box content.
|
|
748
636
|
*/
|
|
749
637
|
public mountContent(content: HTMLElement): this {
|
|
750
|
-
this.
|
|
638
|
+
this.set$userContent(content);
|
|
751
639
|
return this;
|
|
752
640
|
}
|
|
753
641
|
|
|
@@ -755,21 +643,15 @@ export class TeleBox {
|
|
|
755
643
|
* Unmount content from the box.
|
|
756
644
|
*/
|
|
757
645
|
public unmountContent(): this {
|
|
758
|
-
this.
|
|
646
|
+
this.set$userContent(undefined);
|
|
759
647
|
return this;
|
|
760
648
|
}
|
|
761
649
|
|
|
762
|
-
protected _$userFooter: Val<HTMLElement | undefined>;
|
|
763
|
-
|
|
764
|
-
public get $userFooter(): HTMLElement | undefined {
|
|
765
|
-
return this._$userFooter.value;
|
|
766
|
-
}
|
|
767
|
-
|
|
768
650
|
/**
|
|
769
651
|
* Mount dom to box Footer.
|
|
770
652
|
*/
|
|
771
653
|
public mountFooter(footer: HTMLElement): this {
|
|
772
|
-
this.
|
|
654
|
+
this.set$userFooter(footer);
|
|
773
655
|
return this;
|
|
774
656
|
}
|
|
775
657
|
|
|
@@ -777,14 +659,12 @@ export class TeleBox {
|
|
|
777
659
|
* Unmount Footer from the box.
|
|
778
660
|
*/
|
|
779
661
|
public unmountFooter(): this {
|
|
780
|
-
this.
|
|
662
|
+
this.set$userFooter(undefined);
|
|
781
663
|
return this;
|
|
782
664
|
}
|
|
783
665
|
|
|
784
|
-
protected _$userStyles: Val<HTMLStyleElement | undefined>;
|
|
785
|
-
|
|
786
666
|
public getUserStyles(): HTMLStyleElement | undefined {
|
|
787
|
-
return this
|
|
667
|
+
return this.$userStyles;
|
|
788
668
|
}
|
|
789
669
|
|
|
790
670
|
public mountStyles(styles: string | HTMLStyleElement): this {
|
|
@@ -795,12 +675,12 @@ export class TeleBox {
|
|
|
795
675
|
} else {
|
|
796
676
|
$styles = styles;
|
|
797
677
|
}
|
|
798
|
-
this.
|
|
678
|
+
this.set$userStyles($styles);
|
|
799
679
|
return this;
|
|
800
680
|
}
|
|
801
681
|
|
|
802
682
|
public unmountStyles(): this {
|
|
803
|
-
this.
|
|
683
|
+
this.set$userStyles(undefined);
|
|
804
684
|
return this;
|
|
805
685
|
}
|
|
806
686
|
|
|
@@ -848,17 +728,17 @@ export class TeleBox {
|
|
|
848
728
|
});
|
|
849
729
|
};
|
|
850
730
|
|
|
851
|
-
bindClassName(this.$box, this._readonly
|
|
852
|
-
bindClassName(this.$box, this._draggable
|
|
853
|
-
bindClassName(this.$box, this._resizable
|
|
854
|
-
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);
|
|
855
735
|
|
|
856
736
|
this._renderSideEffect.add(() => {
|
|
857
737
|
const minimizedClassName = this.wrapClassName("minimized");
|
|
858
738
|
const maximizedClassName = this.wrapClassName("maximized");
|
|
859
739
|
const MAXIMIZED_TIMER_ID = "box-maximized-timer";
|
|
860
740
|
|
|
861
|
-
return this._state
|
|
741
|
+
return this._state$.subscribe((state) => {
|
|
862
742
|
this.$box.classList.toggle(
|
|
863
743
|
minimizedClassName,
|
|
864
744
|
state === TELE_BOX_STATE.Minimized
|
|
@@ -884,13 +764,13 @@ export class TeleBox {
|
|
|
884
764
|
});
|
|
885
765
|
|
|
886
766
|
this._renderSideEffect.add(() =>
|
|
887
|
-
this._visible
|
|
767
|
+
this._visible$.subscribe((visible) => {
|
|
888
768
|
this.$box.style.display = visible ? "block" : "none";
|
|
889
769
|
})
|
|
890
770
|
);
|
|
891
771
|
|
|
892
772
|
this._renderSideEffect.add(() =>
|
|
893
|
-
this._zIndex
|
|
773
|
+
this._zIndex$.subscribe((zIndex) => {
|
|
894
774
|
this.$box.style.zIndex = String(zIndex);
|
|
895
775
|
})
|
|
896
776
|
);
|
|
@@ -911,14 +791,14 @@ export class TeleBox {
|
|
|
911
791
|
translateY - 10
|
|
912
792
|
}px)`;
|
|
913
793
|
|
|
914
|
-
this.
|
|
915
|
-
|
|
794
|
+
this._valSideEffectBinder
|
|
795
|
+
.combine(
|
|
916
796
|
[
|
|
917
|
-
this._coord
|
|
918
|
-
this._size
|
|
919
|
-
this._minimized
|
|
920
|
-
this._containerRect
|
|
921
|
-
this._collectorRect
|
|
797
|
+
this._coord$,
|
|
798
|
+
this._size$,
|
|
799
|
+
this._minimized$,
|
|
800
|
+
this._containerRect$,
|
|
801
|
+
this._collectorRect$,
|
|
922
802
|
],
|
|
923
803
|
([coord, size, minimized, containerRect, collectorRect]) => {
|
|
924
804
|
const absoluteWidth = size.width * containerRect.width;
|
|
@@ -939,17 +819,11 @@ export class TeleBox {
|
|
|
939
819
|
};
|
|
940
820
|
},
|
|
941
821
|
shallowequal
|
|
942
|
-
)
|
|
943
|
-
|
|
944
|
-
combined.subscribe((styles) => {
|
|
822
|
+
)
|
|
823
|
+
.subscribe((styles) => {
|
|
945
824
|
boxStyler.set(styles);
|
|
946
825
|
});
|
|
947
826
|
|
|
948
|
-
return () => {
|
|
949
|
-
combined.destroy();
|
|
950
|
-
};
|
|
951
|
-
});
|
|
952
|
-
|
|
953
827
|
boxStyler.set({ x: translateX, y: translateY });
|
|
954
828
|
|
|
955
829
|
const $boxMain = document.createElement("div");
|
|
@@ -970,7 +844,7 @@ export class TeleBox {
|
|
|
970
844
|
|
|
971
845
|
this._renderSideEffect.add(() => {
|
|
972
846
|
let last$userStyles: HTMLStyleElement | undefined;
|
|
973
|
-
return this._$userStyles
|
|
847
|
+
return this._$userStyles$.subscribe(($userStyles) => {
|
|
974
848
|
if (last$userStyles) {
|
|
975
849
|
last$userStyles.remove();
|
|
976
850
|
}
|
|
@@ -983,7 +857,7 @@ export class TeleBox {
|
|
|
983
857
|
|
|
984
858
|
this._renderSideEffect.add(() => {
|
|
985
859
|
let last$userContent: HTMLElement | undefined;
|
|
986
|
-
return this._$userContent
|
|
860
|
+
return this._$userContent$.subscribe(($userContent) => {
|
|
987
861
|
if (last$userContent) {
|
|
988
862
|
last$userContent.remove();
|
|
989
863
|
}
|
|
@@ -1002,7 +876,7 @@ export class TeleBox {
|
|
|
1002
876
|
|
|
1003
877
|
this._renderSideEffect.add(() => {
|
|
1004
878
|
let last$userFooter: HTMLElement | undefined;
|
|
1005
|
-
return this._$userFooter
|
|
879
|
+
return this._$userFooter$.subscribe(($userFooter) => {
|
|
1006
880
|
if (last$userFooter) {
|
|
1007
881
|
last$userFooter.remove();
|
|
1008
882
|
}
|
|
@@ -1152,7 +1026,7 @@ export class TeleBox {
|
|
|
1152
1026
|
break;
|
|
1153
1027
|
}
|
|
1154
1028
|
default: {
|
|
1155
|
-
if (this.
|
|
1029
|
+
if (this.fence) {
|
|
1156
1030
|
this.move(
|
|
1157
1031
|
clamp(trackStartX + offsetX, 0, 1 - this.width),
|
|
1158
1032
|
clamp(trackStartY + offsetY, 0, 1 - this.height)
|
|
@@ -1296,12 +1170,6 @@ export class TeleBox {
|
|
|
1296
1170
|
this._renderSideEffect.flushAll();
|
|
1297
1171
|
this.events.removeAllListeners();
|
|
1298
1172
|
this._delegateEvents.removeAllListeners();
|
|
1299
|
-
Object.keys(this).forEach((key) => {
|
|
1300
|
-
const value = this[key as keyof this];
|
|
1301
|
-
if (value instanceof Val) {
|
|
1302
|
-
value.destroy();
|
|
1303
|
-
}
|
|
1304
|
-
});
|
|
1305
1173
|
}
|
|
1306
1174
|
|
|
1307
1175
|
/**
|