@netless/telebox-insider 0.2.16 → 0.2.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/telebox-insider",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "private": false,
5
5
  "description": "Window widget for Whiteboard",
6
6
  "license": "MIT",
@@ -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
- const { x, y, width, height } =
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);
@@ -480,7 +500,6 @@ export class TeleBoxManager {
480
500
  const boxes = this.boxes.slice();
481
501
  const deletedBoxes = boxes.splice(index, 1);
482
502
  this.boxes$.setValue(boxes);
483
- this.focusTopBox();
484
503
  deletedBoxes.forEach((box) => box.destroy());
485
504
  if (!skipUpdate) {
486
505
  if (this.boxes.length <= 0) {
@@ -542,7 +561,6 @@ export class TeleBoxManager {
542
561
  focusChanged = true;
543
562
  targetBox.setFocus(true, skipUpdate);
544
563
  }
545
- this.makeBoxTop(targetBox, skipUpdate);
546
564
  if (focusChanged && !skipUpdate) {
547
565
  this.events.emit(
548
566
  TELE_BOX_MANAGER_EVENT.Focused,