@netless/telebox-insider 0.2.14 → 0.2.18
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/TeleBoxManager/index.d.ts +1 -0
- package/dist/telebox-insider.cjs.js +1 -1
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +1 -1
- package/dist/telebox-insider.es.js.map +1 -1
- package/package.json +1 -1
- package/src/TeleBox/index.ts +1 -1
- package/src/TeleBoxManager/index.ts +42 -16
package/package.json
CHANGED
package/src/TeleBox/index.ts
CHANGED
|
@@ -37,6 +37,7 @@ type ValConfig = {
|
|
|
37
37
|
prefersColorScheme: Val<TeleBoxColorScheme, boolean>;
|
|
38
38
|
containerRect: Val<TeleBoxRect, boolean>;
|
|
39
39
|
collector: Val<TeleBoxCollector | null>;
|
|
40
|
+
collectorRect: Val<TeleBoxRect | undefined>;
|
|
40
41
|
readonly: Val<boolean, boolean>;
|
|
41
42
|
minimized: Val<boolean, boolean>;
|
|
42
43
|
maximized: Val<boolean, boolean>;
|
|
@@ -197,25 +198,36 @@ export class TeleBoxManager {
|
|
|
197
198
|
collector$.value?.setDarkMode(darkMode);
|
|
198
199
|
});
|
|
199
200
|
|
|
201
|
+
const calcCollectorRect = (): TeleBoxRect | undefined => {
|
|
202
|
+
if (collector$.value?.$collector) {
|
|
203
|
+
const { x, y, width, height } =
|
|
204
|
+
collector$.value.$collector.getBoundingClientRect();
|
|
205
|
+
const rootRect = this.root.getBoundingClientRect();
|
|
206
|
+
return {
|
|
207
|
+
x: x - rootRect.x,
|
|
208
|
+
y: y - rootRect.y,
|
|
209
|
+
width,
|
|
210
|
+
height,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const collectorRect$ = createVal(
|
|
217
|
+
minimized$.value ? calcCollectorRect() : void 0
|
|
218
|
+
);
|
|
219
|
+
collectorRect$.subscribe((collectorRect, _, skipUpdate) => {
|
|
220
|
+
this.boxes.forEach((box) => {
|
|
221
|
+
box.setCollectorRect(collectorRect, skipUpdate);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
200
225
|
minimized$.subscribe((minimized, _, skipUpdate) => {
|
|
201
226
|
collector$.value?.setVisible(minimized);
|
|
202
227
|
|
|
203
228
|
if (minimized) {
|
|
204
229
|
if (collector$.value?.$collector) {
|
|
205
|
-
|
|
206
|
-
collector$.value.$collector.getBoundingClientRect();
|
|
207
|
-
const rootRect = this.root.getBoundingClientRect();
|
|
208
|
-
this.boxes.forEach((box) => {
|
|
209
|
-
box.setCollectorRect(
|
|
210
|
-
{
|
|
211
|
-
x: x - rootRect.x,
|
|
212
|
-
y: y - rootRect.y,
|
|
213
|
-
width,
|
|
214
|
-
height,
|
|
215
|
-
},
|
|
216
|
-
true
|
|
217
|
-
);
|
|
218
|
-
});
|
|
230
|
+
collectorRect$.setValue(calcCollectorRect());
|
|
219
231
|
} else if (import.meta.env.DEV) {
|
|
220
232
|
console.warn("No collector for minimized boxes.");
|
|
221
233
|
}
|
|
@@ -255,6 +267,7 @@ export class TeleBoxManager {
|
|
|
255
267
|
const box = this.getBox(id);
|
|
256
268
|
if (box) {
|
|
257
269
|
this.focusBox(box);
|
|
270
|
+
this.makeBoxTop(box);
|
|
258
271
|
return;
|
|
259
272
|
}
|
|
260
273
|
}
|
|
@@ -293,6 +306,7 @@ export class TeleBoxManager {
|
|
|
293
306
|
}
|
|
294
307
|
case TELE_BOX_EVENT.Close: {
|
|
295
308
|
this.removeTopBox();
|
|
309
|
+
this.focusTopBox();
|
|
296
310
|
break;
|
|
297
311
|
}
|
|
298
312
|
default: {
|
|
@@ -315,6 +329,7 @@ export class TeleBoxManager {
|
|
|
315
329
|
prefersColorScheme: prefersColorScheme$,
|
|
316
330
|
containerRect: containerRect$,
|
|
317
331
|
collector: collector$,
|
|
332
|
+
collectorRect: collectorRect$,
|
|
318
333
|
readonly: readonly$,
|
|
319
334
|
fence: fence$,
|
|
320
335
|
minimized: minimized$,
|
|
@@ -393,12 +408,16 @@ export class TeleBoxManager {
|
|
|
393
408
|
namespace: this.namespace,
|
|
394
409
|
containerRect: this.containerRect,
|
|
395
410
|
readonly: this.readonly,
|
|
411
|
+
collectorRect: this.collectorRect,
|
|
396
412
|
});
|
|
397
413
|
|
|
398
414
|
box.mount(this.root);
|
|
399
415
|
|
|
400
416
|
if (box.focus) {
|
|
401
417
|
this.focusBox(box);
|
|
418
|
+
if (smartPosition) {
|
|
419
|
+
this.makeBoxTop(box);
|
|
420
|
+
}
|
|
402
421
|
}
|
|
403
422
|
|
|
404
423
|
this.boxes$.setValue([...this.boxes, box]);
|
|
@@ -411,6 +430,7 @@ export class TeleBoxManager {
|
|
|
411
430
|
});
|
|
412
431
|
box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Close, () => {
|
|
413
432
|
this.remove(box);
|
|
433
|
+
this.focusTopBox();
|
|
414
434
|
});
|
|
415
435
|
box.events.on(TELE_BOX_EVENT.Move, () => {
|
|
416
436
|
this.events.emit(TELE_BOX_MANAGER_EVENT.Move, box);
|
|
@@ -427,6 +447,11 @@ export class TeleBoxManager {
|
|
|
427
447
|
box.events.on(TELE_BOX_EVENT.VisualResize, () => {
|
|
428
448
|
this.events.emit(TELE_BOX_MANAGER_EVENT.VisualResize, box);
|
|
429
449
|
});
|
|
450
|
+
box.events.on(TELE_BOX_EVENT.ZIndex, () => {
|
|
451
|
+
if (this.topBox && box.zIndex > this.topBox.zIndex) {
|
|
452
|
+
this.topBox$.setValue(box);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
430
455
|
this.events.emit(TELE_BOX_MANAGER_EVENT.Created, box);
|
|
431
456
|
|
|
432
457
|
return box;
|
|
@@ -475,7 +500,6 @@ export class TeleBoxManager {
|
|
|
475
500
|
const boxes = this.boxes.slice();
|
|
476
501
|
const deletedBoxes = boxes.splice(index, 1);
|
|
477
502
|
this.boxes$.setValue(boxes);
|
|
478
|
-
this.focusTopBox();
|
|
479
503
|
deletedBoxes.forEach((box) => box.destroy());
|
|
480
504
|
if (!skipUpdate) {
|
|
481
505
|
if (this.boxes.length <= 0) {
|
|
@@ -537,7 +561,6 @@ export class TeleBoxManager {
|
|
|
537
561
|
focusChanged = true;
|
|
538
562
|
targetBox.setFocus(true, skipUpdate);
|
|
539
563
|
}
|
|
540
|
-
this.makeBoxTop(targetBox, skipUpdate);
|
|
541
564
|
if (focusChanged && !skipUpdate) {
|
|
542
565
|
this.events.emit(
|
|
543
566
|
TELE_BOX_MANAGER_EVENT.Focused,
|
|
@@ -643,6 +666,9 @@ export class TeleBoxManager {
|
|
|
643
666
|
if (config.fixRatio != null) {
|
|
644
667
|
box.setFixRatio(config.fixRatio, skipUpdate);
|
|
645
668
|
}
|
|
669
|
+
if (config.zIndex != null) {
|
|
670
|
+
box.setZIndex(config.zIndex);
|
|
671
|
+
}
|
|
646
672
|
if (config.content != null) {
|
|
647
673
|
box.mountContent(config.content);
|
|
648
674
|
}
|