@netless/telebox-insider 0.2.15 → 0.2.19

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.15",
3
+ "version": "0.2.19",
4
4
  "private": false,
5
5
  "description": "Window widget for Whiteboard",
6
6
  "license": "MIT",
@@ -935,7 +935,7 @@ export class TeleBox {
935
935
  }
936
936
  last$userStyles = $userStyles;
937
937
  if ($userStyles) {
938
- $content.appendChild($userStyles);
938
+ $contentWrap.appendChild($userStyles);
939
939
  }
940
940
  });
941
941
  });
@@ -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,21 +430,40 @@ 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
- box.events.on(TELE_BOX_EVENT.Move, () => {
416
- this.events.emit(TELE_BOX_MANAGER_EVENT.Move, box);
435
+ box._coord$.reaction((_, __, skipUpdate) => {
436
+ if (!skipUpdate) {
437
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Move, box);
438
+ }
417
439
  });
418
- box.events.on(TELE_BOX_EVENT.Resize, () => {
419
- this.events.emit(TELE_BOX_MANAGER_EVENT.Resize, box);
440
+ box._size$.reaction((_, __, skipUpdate) => {
441
+ if (!skipUpdate) {
442
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Resize, box);
443
+ }
420
444
  });
421
- box.events.on(TELE_BOX_EVENT.IntrinsicMove, () => {
422
- this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicMove, box);
445
+ box._intrinsicCoord$.reaction((_, __, skipUpdate) => {
446
+ if (!skipUpdate) {
447
+ this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicMove, box);
448
+ }
423
449
  });
424
- box.events.on(TELE_BOX_EVENT.IntrinsicResize, () => {
425
- this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicResize, box);
450
+ box._intrinsicSize$.reaction((_, __, skipUpdate) => {
451
+ if (!skipUpdate) {
452
+ this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicResize, box);
453
+ }
426
454
  });
427
- box.events.on(TELE_BOX_EVENT.VisualResize, () => {
428
- this.events.emit(TELE_BOX_MANAGER_EVENT.VisualResize, box);
455
+ box._visualSize$.reaction((_, __, skipUpdate) => {
456
+ if (!skipUpdate) {
457
+ this.events.emit(TELE_BOX_MANAGER_EVENT.VisualResize, box);
458
+ }
459
+ });
460
+ box._zIndex$.reaction((_, __, skipUpdate) => {
461
+ if (this.topBox && box.zIndex > this.topBox.zIndex) {
462
+ this.topBox$.setValue(box);
463
+ }
464
+ if (!skipUpdate) {
465
+ this.events.emit(TELE_BOX_MANAGER_EVENT.ZIndex, box);
466
+ }
429
467
  });
430
468
  this.events.emit(TELE_BOX_MANAGER_EVENT.Created, box);
431
469
 
@@ -475,7 +513,6 @@ export class TeleBoxManager {
475
513
  const boxes = this.boxes.slice();
476
514
  const deletedBoxes = boxes.splice(index, 1);
477
515
  this.boxes$.setValue(boxes);
478
- this.focusTopBox();
479
516
  deletedBoxes.forEach((box) => box.destroy());
480
517
  if (!skipUpdate) {
481
518
  if (this.boxes.length <= 0) {
@@ -537,7 +574,6 @@ export class TeleBoxManager {
537
574
  focusChanged = true;
538
575
  targetBox.setFocus(true, skipUpdate);
539
576
  }
540
- this.makeBoxTop(targetBox, skipUpdate);
541
577
  if (focusChanged && !skipUpdate) {
542
578
  this.events.emit(
543
579
  TELE_BOX_MANAGER_EVENT.Focused,
@@ -635,16 +671,16 @@ export class TeleBoxManager {
635
671
  box.setMinWidth(config.minWidth, skipUpdate);
636
672
  }
637
673
  if (config.resizable != null) {
638
- box.setResizable(config.resizable);
674
+ box.setResizable(config.resizable, skipUpdate);
639
675
  }
640
676
  if (config.draggable != null) {
641
- box.setDraggable(config.draggable);
677
+ box.setDraggable(config.draggable, skipUpdate);
642
678
  }
643
679
  if (config.fixRatio != null) {
644
680
  box.setFixRatio(config.fixRatio, skipUpdate);
645
681
  }
646
682
  if (config.zIndex != null) {
647
- box.setZIndex(config.zIndex);
683
+ box.setZIndex(config.zIndex, skipUpdate);
648
684
  }
649
685
  if (config.content != null) {
650
686
  box.mountContent(config.content);
@@ -699,9 +735,6 @@ export class TeleBoxManager {
699
735
  if (box !== this.topBox) {
700
736
  box.setZIndex(this.topBox.zIndex + 1, skipUpdate);
701
737
  this.topBox$.setValue(box);
702
- if (!skipUpdate) {
703
- this.events.emit(TELE_BOX_MANAGER_EVENT.ZIndex, box);
704
- }
705
738
  }
706
739
  }
707
740
  }