@netless/telebox-insider 0.2.9 → 0.2.13
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 +1 -0
- package/dist/TeleBox/typings.d.ts +1 -0
- package/dist/TeleBoxManager/MaxTitleBar/index.d.ts +1 -1
- package/dist/TeleBoxManager/constants.d.ts +2 -0
- package/dist/TeleBoxManager/index.d.ts +16 -18
- package/dist/TeleBoxManager/typings.d.ts +7 -6
- 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 +1 -1
- package/src/TeleBox/constants.ts +1 -0
- package/src/TeleBox/index.ts +26 -12
- package/src/TeleBox/typings.ts +1 -0
- package/src/TeleBoxManager/MaxTitleBar/index.ts +1 -5
- package/src/TeleBoxManager/constants.ts +2 -0
- package/src/TeleBoxManager/index.ts +190 -159
- package/src/TeleBoxManager/typings.ts +6 -6
package/package.json
CHANGED
package/src/TeleBox/constants.ts
CHANGED
package/src/TeleBox/index.ts
CHANGED
|
@@ -140,24 +140,28 @@ export class TeleBox {
|
|
|
140
140
|
const prefersDark = window.matchMedia(
|
|
141
141
|
"(prefers-color-scheme: dark)"
|
|
142
142
|
);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
darkMode$.setValue(evt.matches, skipUpdate);
|
|
148
|
-
};
|
|
149
|
-
prefersDark.addEventListener("change", handler);
|
|
150
|
-
return () =>
|
|
151
|
-
prefersDark.removeEventListener(
|
|
152
|
-
"change",
|
|
153
|
-
handler
|
|
143
|
+
if (prefersDark) {
|
|
144
|
+
darkMode$.setValue(
|
|
145
|
+
prefersDark.matches,
|
|
146
|
+
skipUpdate
|
|
154
147
|
);
|
|
148
|
+
const handler = (
|
|
149
|
+
evt: MediaQueryListEvent
|
|
150
|
+
): void => {
|
|
151
|
+
darkMode$.setValue(evt.matches, skipUpdate);
|
|
152
|
+
};
|
|
153
|
+
prefersDark.addListener(handler);
|
|
154
|
+
return () =>
|
|
155
|
+
prefersDark.removeListener(handler);
|
|
156
|
+
} else {
|
|
157
|
+
return noop;
|
|
158
|
+
}
|
|
155
159
|
} else {
|
|
156
160
|
darkMode$.setValue(
|
|
157
161
|
prefersColorScheme === "dark",
|
|
158
162
|
skipUpdate
|
|
159
163
|
);
|
|
160
|
-
return
|
|
164
|
+
return noop;
|
|
161
165
|
}
|
|
162
166
|
}, "prefers-color-scheme");
|
|
163
167
|
}
|
|
@@ -193,7 +197,13 @@ export class TeleBox {
|
|
|
193
197
|
const draggable$ = createVal(draggable);
|
|
194
198
|
const fence$ = createVal(fence);
|
|
195
199
|
const fixRatio$ = createVal(fixRatio);
|
|
200
|
+
|
|
196
201
|
const zIndex$ = createVal(zIndex);
|
|
202
|
+
zIndex$.reaction((zIndex, _, skipUpdate) => {
|
|
203
|
+
if (!skipUpdate) {
|
|
204
|
+
this.events.emit(TELE_BOX_EVENT.ZIndex, zIndex);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
197
207
|
|
|
198
208
|
const focus$ = createVal(focus);
|
|
199
209
|
focus$.reaction((focus, _, skipUpdate) => {
|
|
@@ -1255,6 +1265,10 @@ export class TeleBox {
|
|
|
1255
1265
|
}
|
|
1256
1266
|
}
|
|
1257
1267
|
|
|
1268
|
+
function noop(): void {
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1258
1272
|
type PropKeys<K = keyof TeleBox> = K extends keyof TeleBox
|
|
1259
1273
|
? TeleBox[K] extends Function
|
|
1260
1274
|
? never
|
package/src/TeleBox/typings.ts
CHANGED
|
@@ -96,6 +96,7 @@ export type TeleBoxEventConfig = CheckTeleBoxConfig<{
|
|
|
96
96
|
intrinsic_move: { x: number; y: number };
|
|
97
97
|
intrinsic_resize: { width: number; height: number };
|
|
98
98
|
visual_resize: { width: number; height: number };
|
|
99
|
+
z_index: number;
|
|
99
100
|
state: TeleBoxState;
|
|
100
101
|
minimized: boolean;
|
|
101
102
|
maximized: boolean;
|
|
@@ -25,10 +25,6 @@ export class MaxTitleBar extends DefaultTitleBar {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
public focusBox(box?: MaxTitleBarTeleBox): void {
|
|
28
|
-
if (!box) {
|
|
29
|
-
box = this.boxes[this.boxes.length - 1];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
28
|
if (this.focusedBox && this.focusedBox === box) {
|
|
33
29
|
return;
|
|
34
30
|
}
|
|
@@ -200,7 +196,7 @@ export class MaxTitleBar extends DefaultTitleBar {
|
|
|
200
196
|
|
|
201
197
|
protected boxes: MaxTitleBarTeleBox[];
|
|
202
198
|
|
|
203
|
-
|
|
199
|
+
public focusedBox: MaxTitleBarTeleBox | undefined;
|
|
204
200
|
|
|
205
201
|
protected containerRect: TeleBoxRect;
|
|
206
202
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export enum TELE_BOX_MANAGER_EVENT {
|
|
2
2
|
Focused = "focused",
|
|
3
|
+
Blurred = "blurred",
|
|
3
4
|
Created = "created",
|
|
4
5
|
Removed = "removed",
|
|
5
6
|
State = "state",
|
|
@@ -10,6 +11,7 @@ export enum TELE_BOX_MANAGER_EVENT {
|
|
|
10
11
|
IntrinsicMove = "intrinsic_move",
|
|
11
12
|
IntrinsicResize = "intrinsic_resize",
|
|
12
13
|
VisualResize = "visual_resize",
|
|
14
|
+
ZIndex = "z_index",
|
|
13
15
|
PrefersColorScheme = "prefers_color_scheme",
|
|
14
16
|
DarkMode = "dark_mode",
|
|
15
17
|
}
|
|
@@ -59,7 +59,6 @@ export class TeleBoxManager {
|
|
|
59
59
|
},
|
|
60
60
|
collector,
|
|
61
61
|
namespace = "telebox",
|
|
62
|
-
zIndex = 100,
|
|
63
62
|
readonly = false,
|
|
64
63
|
}: TeleBoxManagerConfig = {}) {
|
|
65
64
|
this._sideEffect = new SideEffectManager();
|
|
@@ -67,18 +66,32 @@ export class TeleBoxManager {
|
|
|
67
66
|
|
|
68
67
|
this.root = root;
|
|
69
68
|
this.namespace = namespace;
|
|
70
|
-
this.zIndex = zIndex;
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
this.boxes$ = createVal<TeleBox[]>([]);
|
|
71
|
+
this.topBox$ = this.boxes$.derive((boxes) => {
|
|
72
|
+
if (boxes.length > 0) {
|
|
73
|
+
const topBox = boxes.reduce((topBox, box) =>
|
|
74
|
+
topBox.zIndex > box.zIndex ? topBox : box
|
|
75
|
+
);
|
|
76
|
+
return topBox;
|
|
77
|
+
}
|
|
78
|
+
return;
|
|
80
79
|
});
|
|
81
80
|
|
|
81
|
+
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
|
|
82
|
+
const prefersDark$ = createVal(false);
|
|
83
|
+
|
|
84
|
+
if (prefersDark) {
|
|
85
|
+
prefersDark$.setValue(prefersDark.matches);
|
|
86
|
+
this._sideEffect.add(() => {
|
|
87
|
+
const handler = (evt: MediaQueryListEvent): void => {
|
|
88
|
+
prefersDark$.setValue(evt.matches);
|
|
89
|
+
};
|
|
90
|
+
prefersDark.addListener(handler);
|
|
91
|
+
return () => prefersDark.removeListener(handler);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
82
95
|
const prefersColorScheme$ = createVal(prefersColorScheme);
|
|
83
96
|
prefersColorScheme$.reaction((prefersColorScheme, _, skipUpdate) => {
|
|
84
97
|
this.boxes.forEach((box) =>
|
|
@@ -217,6 +230,8 @@ export class TeleBoxManager {
|
|
|
217
230
|
}
|
|
218
231
|
});
|
|
219
232
|
|
|
233
|
+
const closeBtnClassName = this.wrapClassName("titlebar-icon-close");
|
|
234
|
+
|
|
220
235
|
const checkFocusBox = (ev: MouseEvent | TouchEvent): void => {
|
|
221
236
|
if (readonly$.value) {
|
|
222
237
|
return;
|
|
@@ -232,11 +247,14 @@ export class TeleBoxManager {
|
|
|
232
247
|
el;
|
|
233
248
|
el = el.parentElement
|
|
234
249
|
) {
|
|
250
|
+
if (el.classList && el.classList.contains(closeBtnClassName)) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
235
253
|
const id = el.dataset?.teleBoxID;
|
|
236
254
|
if (id) {
|
|
237
|
-
const box = this.
|
|
255
|
+
const box = this.getBox(id);
|
|
238
256
|
if (box) {
|
|
239
|
-
this.focusBox(
|
|
257
|
+
this.focusBox(box);
|
|
240
258
|
return;
|
|
241
259
|
}
|
|
242
260
|
}
|
|
@@ -261,8 +279,7 @@ export class TeleBoxManager {
|
|
|
261
279
|
readonly: readonly$.value,
|
|
262
280
|
namespace: this.namespace,
|
|
263
281
|
state: state$.value,
|
|
264
|
-
boxes: this.boxes,
|
|
265
|
-
focusedBox: this._focusedBox,
|
|
282
|
+
boxes: this.boxes$.value,
|
|
266
283
|
containerRect: containerRect$.value,
|
|
267
284
|
onEvent: (event): void => {
|
|
268
285
|
switch (event.type) {
|
|
@@ -275,12 +292,7 @@ export class TeleBoxManager {
|
|
|
275
292
|
break;
|
|
276
293
|
}
|
|
277
294
|
case TELE_BOX_EVENT.Close: {
|
|
278
|
-
|
|
279
|
-
this._focusedBox ??
|
|
280
|
-
this.boxes[this.boxes.length - 1];
|
|
281
|
-
if (box) {
|
|
282
|
-
this.remove(box.id);
|
|
283
|
-
}
|
|
295
|
+
this.removeTopBox();
|
|
284
296
|
break;
|
|
285
297
|
}
|
|
286
298
|
default: {
|
|
@@ -295,6 +307,9 @@ export class TeleBoxManager {
|
|
|
295
307
|
this._darkMode$.subscribe((darkMode) => {
|
|
296
308
|
this.maxTitleBar.setDarkMode(darkMode);
|
|
297
309
|
});
|
|
310
|
+
this.boxes$.reaction((boxes) => {
|
|
311
|
+
this.maxTitleBar.setBoxes(boxes);
|
|
312
|
+
});
|
|
298
313
|
|
|
299
314
|
const valConfig: ValConfig = {
|
|
300
315
|
prefersColorScheme: prefersColorScheme$,
|
|
@@ -313,6 +328,14 @@ export class TeleBoxManager {
|
|
|
313
328
|
this.root.appendChild(this.maxTitleBar.render());
|
|
314
329
|
}
|
|
315
330
|
|
|
331
|
+
public get boxes(): ReadonlyArray<TeleBox> {
|
|
332
|
+
return this.boxes$.value;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
public get topBox(): TeleBox | undefined {
|
|
336
|
+
return this.topBox$.value;
|
|
337
|
+
}
|
|
338
|
+
|
|
316
339
|
public readonly events = new EventEmitter() as TeleBoxManagerEvents;
|
|
317
340
|
|
|
318
341
|
protected _sideEffect: SideEffectManager;
|
|
@@ -321,8 +344,6 @@ export class TeleBoxManager {
|
|
|
321
344
|
|
|
322
345
|
public readonly namespace: string;
|
|
323
346
|
|
|
324
|
-
public zIndex: number;
|
|
325
|
-
|
|
326
347
|
public _darkMode$: Val<boolean, boolean>;
|
|
327
348
|
|
|
328
349
|
public get darkMode(): boolean {
|
|
@@ -357,16 +378,30 @@ export class TeleBoxManager {
|
|
|
357
378
|
return this;
|
|
358
379
|
}
|
|
359
380
|
|
|
360
|
-
public create(
|
|
361
|
-
|
|
381
|
+
public create(
|
|
382
|
+
config: TeleBoxManagerCreateConfig = {},
|
|
383
|
+
smartPosition = true
|
|
384
|
+
): ReadonlyTeleBox {
|
|
385
|
+
const box = new TeleBox({
|
|
386
|
+
zIndex: this.topBox ? this.topBox.zIndex + 1 : 100,
|
|
387
|
+
...(smartPosition ? this.smartPosition(config) : config),
|
|
388
|
+
darkMode: this.darkMode,
|
|
389
|
+
prefersColorScheme: this.prefersColorScheme,
|
|
390
|
+
maximized: this.maximized,
|
|
391
|
+
minimized: this.minimized,
|
|
392
|
+
fence: this.fence,
|
|
393
|
+
namespace: this.namespace,
|
|
394
|
+
containerRect: this.containerRect,
|
|
395
|
+
readonly: this.readonly,
|
|
396
|
+
});
|
|
397
|
+
|
|
362
398
|
box.mount(this.root);
|
|
363
|
-
this.boxes.push(box);
|
|
364
399
|
|
|
365
400
|
if (box.focus) {
|
|
366
|
-
this.focusBox(
|
|
401
|
+
this.focusBox(box);
|
|
367
402
|
}
|
|
368
403
|
|
|
369
|
-
this.
|
|
404
|
+
this.boxes$.setValue([...this.boxes, box]);
|
|
370
405
|
|
|
371
406
|
box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Maximize, () => {
|
|
372
407
|
this.setMaximized(!this.maximized);
|
|
@@ -375,8 +410,7 @@ export class TeleBoxManager {
|
|
|
375
410
|
this.setMinimized(true);
|
|
376
411
|
});
|
|
377
412
|
box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Close, () => {
|
|
378
|
-
this.
|
|
379
|
-
this.remove(box.id);
|
|
413
|
+
this.remove(box);
|
|
380
414
|
});
|
|
381
415
|
box.events.on(TELE_BOX_EVENT.Move, () => {
|
|
382
416
|
this.events.emit(TELE_BOX_MANAGER_EVENT.Move, box);
|
|
@@ -433,57 +467,52 @@ export class TeleBoxManager {
|
|
|
433
467
|
}
|
|
434
468
|
|
|
435
469
|
public remove(
|
|
436
|
-
|
|
470
|
+
boxOrID: string | TeleBox,
|
|
437
471
|
skipUpdate = false
|
|
438
472
|
): ReadonlyTeleBox | undefined {
|
|
439
|
-
const index = this.
|
|
473
|
+
const index = this.getBoxIndex(boxOrID);
|
|
440
474
|
if (index >= 0) {
|
|
441
|
-
const boxes = this.boxes.
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
this.
|
|
445
|
-
box.destroy
|
|
475
|
+
const boxes = this.boxes.slice();
|
|
476
|
+
const deletedBoxes = boxes.splice(index, 1);
|
|
477
|
+
this.boxes$.setValue(boxes);
|
|
478
|
+
this.focusTopBox();
|
|
479
|
+
deletedBoxes.forEach((box) => box.destroy);
|
|
446
480
|
if (!skipUpdate) {
|
|
447
481
|
if (this.boxes.length <= 0) {
|
|
448
482
|
this.setMaximized(false);
|
|
449
483
|
this.setMinimized(false);
|
|
450
484
|
}
|
|
451
|
-
this.events.emit(TELE_BOX_MANAGER_EVENT.Removed,
|
|
485
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Removed, deletedBoxes);
|
|
452
486
|
}
|
|
453
|
-
return
|
|
487
|
+
return deletedBoxes[0];
|
|
454
488
|
}
|
|
455
489
|
return;
|
|
456
490
|
}
|
|
457
491
|
|
|
458
|
-
public
|
|
459
|
-
if (this.
|
|
460
|
-
|
|
461
|
-
this._focusedBox = void 0;
|
|
462
|
-
if (!skipUpdate) {
|
|
463
|
-
this.events.emit(
|
|
464
|
-
TELE_BOX_MANAGER_EVENT.Focused,
|
|
465
|
-
undefined,
|
|
466
|
-
box
|
|
467
|
-
);
|
|
468
|
-
}
|
|
492
|
+
public removeTopBox(): ReadonlyTeleBox | undefined {
|
|
493
|
+
if (this.topBox) {
|
|
494
|
+
return this.remove(this.topBox);
|
|
469
495
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
public removeAll(skipUpdate = false): ReadonlyTeleBox[] {
|
|
500
|
+
const deletedBoxes = this.boxes$.value;
|
|
501
|
+
this.boxes$.setValue([]);
|
|
502
|
+
deletedBoxes.forEach((box) => box.destroy());
|
|
473
503
|
if (!skipUpdate) {
|
|
474
504
|
if (this.boxes.length <= 0) {
|
|
475
505
|
this.setMaximized(false);
|
|
476
506
|
this.setMinimized(false);
|
|
477
507
|
}
|
|
478
|
-
this.events.emit(TELE_BOX_MANAGER_EVENT.Removed,
|
|
508
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Removed, deletedBoxes);
|
|
479
509
|
}
|
|
480
|
-
return
|
|
510
|
+
return deletedBoxes;
|
|
481
511
|
}
|
|
482
512
|
|
|
483
513
|
public destroy(skipUpdate = false): void {
|
|
484
514
|
this.events.removeAllListeners();
|
|
485
515
|
this._sideEffect.flushAll();
|
|
486
|
-
this._focusedBox = void 0;
|
|
487
516
|
this.removeAll(skipUpdate);
|
|
488
517
|
|
|
489
518
|
Object.keys(this).forEach((key) => {
|
|
@@ -498,13 +527,70 @@ export class TeleBoxManager {
|
|
|
498
527
|
return `${this.namespace}-${className}`;
|
|
499
528
|
}
|
|
500
529
|
|
|
501
|
-
|
|
530
|
+
public focusBox(boxOrID: string | TeleBox, skipUpdate = false): void {
|
|
531
|
+
const targetBox = this.getBox(boxOrID);
|
|
532
|
+
if (targetBox) {
|
|
533
|
+
this.boxes.forEach((box) => {
|
|
534
|
+
if (targetBox === box) {
|
|
535
|
+
let focusChanged = false;
|
|
536
|
+
if (!targetBox.focus) {
|
|
537
|
+
focusChanged = true;
|
|
538
|
+
targetBox.setFocus(true, skipUpdate);
|
|
539
|
+
}
|
|
540
|
+
this.makeBoxTop(targetBox, skipUpdate);
|
|
541
|
+
if (focusChanged && !skipUpdate) {
|
|
542
|
+
this.events.emit(
|
|
543
|
+
TELE_BOX_MANAGER_EVENT.Focused,
|
|
544
|
+
targetBox
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
} else if (box.focus) {
|
|
548
|
+
this.blurBox(box, skipUpdate);
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
this.maxTitleBar.focusBox(targetBox);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
public focusTopBox(): void {
|
|
556
|
+
if (this.topBox && !this.topBox.focus) {
|
|
557
|
+
return this.focusBox(this.topBox);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
public blurBox(boxOrID: string | TeleBox, skipUpdate = false): void {
|
|
562
|
+
const targetBox = this.getBox(boxOrID);
|
|
563
|
+
if (targetBox) {
|
|
564
|
+
if (targetBox.focus) {
|
|
565
|
+
targetBox.setFocus(false, skipUpdate);
|
|
566
|
+
if (!skipUpdate) {
|
|
567
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Blurred, targetBox);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
if (this.maxTitleBar.focusedBox === targetBox) {
|
|
571
|
+
this.maxTitleBar.focusBox();
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
502
575
|
|
|
503
|
-
|
|
576
|
+
public blurAll(skipUpdate = false): void {
|
|
577
|
+
this.boxes.forEach((box) => {
|
|
578
|
+
if (box.focus) {
|
|
579
|
+
box.setFocus(false, skipUpdate);
|
|
580
|
+
if (!skipUpdate) {
|
|
581
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Blurred, box);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
if (this.maxTitleBar.focusedBox) {
|
|
586
|
+
this.maxTitleBar.focusBox();
|
|
587
|
+
}
|
|
588
|
+
}
|
|
504
589
|
|
|
505
|
-
protected
|
|
590
|
+
protected maxTitleBar: MaxTitleBar;
|
|
506
591
|
|
|
507
|
-
protected
|
|
592
|
+
protected boxes$: Val<TeleBox[]>;
|
|
593
|
+
protected topBox$: Val<TeleBox | undefined>;
|
|
508
594
|
|
|
509
595
|
protected teleBoxMatcher(
|
|
510
596
|
config: TeleBoxManagerQueryConfig
|
|
@@ -557,9 +643,6 @@ export class TeleBoxManager {
|
|
|
557
643
|
if (config.fixRatio != null) {
|
|
558
644
|
box.setFixRatio(config.fixRatio, skipUpdate);
|
|
559
645
|
}
|
|
560
|
-
if (config.focus != null) {
|
|
561
|
-
this.focusBox({ focus: config.focus, box, skipUpdate });
|
|
562
|
-
}
|
|
563
646
|
if (config.content != null) {
|
|
564
647
|
box.mountContent(config.content);
|
|
565
648
|
}
|
|
@@ -568,119 +651,67 @@ export class TeleBoxManager {
|
|
|
568
651
|
}
|
|
569
652
|
}
|
|
570
653
|
|
|
571
|
-
protected
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
skipUpdate = false,
|
|
575
|
-
increaseZIndex = true,
|
|
576
|
-
}: {
|
|
577
|
-
focus: boolean;
|
|
578
|
-
box: TeleBox;
|
|
579
|
-
skipUpdate?: boolean;
|
|
580
|
-
increaseZIndex?: boolean;
|
|
581
|
-
}): void {
|
|
582
|
-
box.setFocus(focus, skipUpdate);
|
|
583
|
-
if (box.focus) {
|
|
584
|
-
if (this._focusedBox !== box) {
|
|
585
|
-
const lastFocusedBox = this._focusedBox;
|
|
586
|
-
if (this._focusedBox) {
|
|
587
|
-
this._focusedBox.setFocus(false, skipUpdate);
|
|
588
|
-
}
|
|
589
|
-
this._focusedBox = box;
|
|
590
|
-
if (increaseZIndex) {
|
|
591
|
-
box.setZIndex(++this.zIndex);
|
|
592
|
-
}
|
|
593
|
-
if (!skipUpdate) {
|
|
594
|
-
this.events.emit(
|
|
595
|
-
TELE_BOX_MANAGER_EVENT.Focused,
|
|
596
|
-
box,
|
|
597
|
-
lastFocusedBox
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
} else {
|
|
602
|
-
if (this._focusedBox === box) {
|
|
603
|
-
this._focusedBox = void 0;
|
|
654
|
+
protected smartPosition(config: TeleBoxConfig = {}): TeleBoxConfig {
|
|
655
|
+
let { x, y } = config;
|
|
656
|
+
const { width = 0.5, height = 0.5 } = config;
|
|
604
657
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
658
|
+
if (x == null) {
|
|
659
|
+
let vx = 20;
|
|
660
|
+
if (this.topBox) {
|
|
661
|
+
vx = this.topBox.intrinsicX * this.containerRect.width + 20;
|
|
662
|
+
|
|
663
|
+
if (
|
|
664
|
+
vx >
|
|
665
|
+
this.containerRect.width - width * this.containerRect.width
|
|
666
|
+
) {
|
|
667
|
+
vx = 20;
|
|
611
668
|
}
|
|
612
669
|
}
|
|
670
|
+
x = vx / this.containerRect.width;
|
|
613
671
|
}
|
|
614
|
-
this.maxTitleBar.focusBox(this._focusedBox);
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
protected getInitialPosition(
|
|
618
|
-
width: number,
|
|
619
|
-
height: number
|
|
620
|
-
): { x: number; y: number } {
|
|
621
|
-
const upMostBox =
|
|
622
|
-
this.boxes.length > 0 &&
|
|
623
|
-
this.boxes.reduce((box1, box2) =>
|
|
624
|
-
box1.zIndex > box2.zIndex ? box1 : box2
|
|
625
|
-
);
|
|
626
672
|
|
|
627
|
-
|
|
628
|
-
|
|
673
|
+
if (y == null) {
|
|
674
|
+
let vy = 20;
|
|
629
675
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
y = upMostBox.intrinsicY * this.containerRect.height + 20;
|
|
676
|
+
if (this.topBox) {
|
|
677
|
+
vy = this.topBox.intrinsicY * this.containerRect.height + 20;
|
|
633
678
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
this.containerRect.width -
|
|
637
|
-
width * this.containerRect.width ||
|
|
638
|
-
y >
|
|
679
|
+
if (
|
|
680
|
+
vy >
|
|
639
681
|
this.containerRect.height -
|
|
640
682
|
height * this.containerRect.height
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
683
|
+
) {
|
|
684
|
+
vy = 20;
|
|
685
|
+
}
|
|
644
686
|
}
|
|
687
|
+
|
|
688
|
+
y = vy / this.containerRect.height;
|
|
645
689
|
}
|
|
646
690
|
|
|
647
|
-
return {
|
|
648
|
-
x: x / this.containerRect.width,
|
|
649
|
-
y: y / this.containerRect.height,
|
|
650
|
-
};
|
|
691
|
+
return { ...config, x, y, width, height };
|
|
651
692
|
}
|
|
652
693
|
|
|
653
|
-
protected
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
x = initialPos.x;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
if (y == null) {
|
|
665
|
-
y = initialPos.y;
|
|
694
|
+
protected makeBoxTop(box: TeleBox, skipUpdate = false): void {
|
|
695
|
+
if (this.topBox) {
|
|
696
|
+
if (box !== this.topBox) {
|
|
697
|
+
box.setZIndex(this.topBox.zIndex + 1, skipUpdate);
|
|
698
|
+
this.topBox$.setValue(box);
|
|
699
|
+
if (!skipUpdate) {
|
|
700
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.ZIndex, box);
|
|
701
|
+
}
|
|
666
702
|
}
|
|
667
703
|
}
|
|
704
|
+
}
|
|
668
705
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
fence: this.fence,
|
|
680
|
-
zIndex: this.zIndex,
|
|
681
|
-
namespace: this.namespace,
|
|
682
|
-
containerRect: this.containerRect,
|
|
683
|
-
readonly: this.readonly,
|
|
684
|
-
};
|
|
706
|
+
protected getBoxIndex(boxOrID: TeleBox | string): number {
|
|
707
|
+
return typeof boxOrID === "string"
|
|
708
|
+
? this.boxes.findIndex((box) => box.id === boxOrID)
|
|
709
|
+
: this.boxes.findIndex((box) => box === boxOrID);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
protected getBox(boxOrID: TeleBox | string): TeleBox | undefined {
|
|
713
|
+
return typeof boxOrID === "string"
|
|
714
|
+
? this.boxes.find((box) => box.id === boxOrID)
|
|
715
|
+
: boxOrID;
|
|
685
716
|
}
|
|
686
717
|
}
|
|
@@ -14,7 +14,6 @@ export interface TeleBoxManagerConfig
|
|
|
14
14
|
| "maximized"
|
|
15
15
|
| "minimized"
|
|
16
16
|
| "namespace"
|
|
17
|
-
| "zIndex"
|
|
18
17
|
| "readonly"
|
|
19
18
|
> {
|
|
20
19
|
/** Element to mount boxes. */
|
|
@@ -35,16 +34,16 @@ type TeleBoxManagerBoxConfigBaseProps =
|
|
|
35
34
|
| "resizable"
|
|
36
35
|
| "draggable"
|
|
37
36
|
| "fixRatio"
|
|
38
|
-
| "
|
|
37
|
+
| "zIndex";
|
|
39
38
|
|
|
40
39
|
export type TeleBoxManagerCreateConfig = Pick<
|
|
41
40
|
TeleBoxConfig,
|
|
42
|
-
TeleBoxManagerBoxConfigBaseProps | "content" | "footer" | "id"
|
|
41
|
+
TeleBoxManagerBoxConfigBaseProps | "content" | "footer" | "id" | "focus"
|
|
43
42
|
>;
|
|
44
43
|
|
|
45
44
|
export type TeleBoxManagerQueryConfig = Pick<
|
|
46
45
|
TeleBoxConfig,
|
|
47
|
-
TeleBoxManagerBoxConfigBaseProps | "id"
|
|
46
|
+
TeleBoxManagerBoxConfigBaseProps | "id" | "focus"
|
|
48
47
|
>;
|
|
49
48
|
|
|
50
49
|
export type TeleBoxManagerUpdateConfig = Pick<
|
|
@@ -57,8 +56,8 @@ type CheckTeleBoxManagerConfig<
|
|
|
57
56
|
> = T;
|
|
58
57
|
|
|
59
58
|
export type TeleBoxManagerEventConfig = CheckTeleBoxManagerConfig<{
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
focused: [ReadonlyTeleBox | undefined];
|
|
60
|
+
blurred: [ReadonlyTeleBox | undefined];
|
|
62
61
|
created: [ReadonlyTeleBox];
|
|
63
62
|
removed: [ReadonlyTeleBox[]];
|
|
64
63
|
state: [TeleBoxState];
|
|
@@ -69,6 +68,7 @@ export type TeleBoxManagerEventConfig = CheckTeleBoxManagerConfig<{
|
|
|
69
68
|
intrinsic_move: [ReadonlyTeleBox];
|
|
70
69
|
intrinsic_resize: [ReadonlyTeleBox];
|
|
71
70
|
visual_resize: [ReadonlyTeleBox];
|
|
71
|
+
z_index: [ReadonlyTeleBox];
|
|
72
72
|
prefers_color_scheme: [TeleBoxColorScheme];
|
|
73
73
|
dark_mode: [boolean];
|
|
74
74
|
}>;
|