microboard-temp 0.13.26 → 0.13.28

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.
@@ -36852,6 +36852,9 @@ class FloatingPoint extends Point {
36852
36852
  relativePoint;
36853
36853
  pointType = "Floating";
36854
36854
  edge;
36855
+ getEdge() {
36856
+ return this.edge;
36857
+ }
36855
36858
  constructor(item, relativePoint) {
36856
36859
  super();
36857
36860
  this.item = item;
@@ -36893,6 +36896,9 @@ class FixedPoint extends Point {
36893
36896
  relativePoint;
36894
36897
  pointType = "Fixed";
36895
36898
  edge;
36899
+ getEdge() {
36900
+ return this.edge;
36901
+ }
36896
36902
  constructor(item, relativePoint) {
36897
36903
  super();
36898
36904
  this.item = item;
@@ -37806,6 +37812,7 @@ class Connector2 extends BaseItem {
37806
37812
  const point5 = this.startPoint;
37807
37813
  if (point5.pointType !== "Board") {
37808
37814
  point5.recalculatePoint();
37815
+ this.smartJumpStartEdge();
37809
37816
  this.updatePaths();
37810
37817
  this.subject.publish(this);
37811
37818
  }
@@ -37814,10 +37821,47 @@ class Connector2 extends BaseItem {
37814
37821
  const point5 = this.endPoint;
37815
37822
  if (point5.pointType !== "Board") {
37816
37823
  point5.recalculatePoint();
37824
+ this.smartJumpStartEdge();
37817
37825
  this.updatePaths();
37818
37826
  this.subject.publish(this);
37819
37827
  }
37820
37828
  };
37829
+ smartJumpStartEdge() {
37830
+ const start = this.startPoint;
37831
+ if (start.pointType !== "Fixed" && start.pointType !== "Floating")
37832
+ return;
37833
+ const startEdge = start.getEdge();
37834
+ if (!startEdge)
37835
+ return;
37836
+ const item = start.item;
37837
+ const anchors = item.getSnapAnchorPoints?.();
37838
+ if (!anchors || anchors.length === 0)
37839
+ return;
37840
+ const center = item.getMbr().getCenter();
37841
+ const dx = this.endPoint.x - center.x;
37842
+ const dy = this.endPoint.y - center.y;
37843
+ if (dx === 0 && dy === 0)
37844
+ return;
37845
+ let best = anchors[0];
37846
+ let bestDot = -Infinity;
37847
+ for (const anchor of anchors) {
37848
+ const ax = anchor.x - center.x;
37849
+ const ay = anchor.y - center.y;
37850
+ const len = Math.sqrt(ax * ax + ay * ay);
37851
+ if (len === 0)
37852
+ continue;
37853
+ const dot = (ax * dx + ay * dy) / len;
37854
+ if (dot > bestDot) {
37855
+ bestDot = dot;
37856
+ best = anchor;
37857
+ }
37858
+ }
37859
+ const bestRel = toRelativePoint(best, item);
37860
+ const cur = start.relativePoint;
37861
+ if (Math.abs(bestRel.x - cur.x) < 0.5 && Math.abs(bestRel.y - cur.y) < 0.5)
37862
+ return;
37863
+ this.startPoint = new FixedPoint(item, bestRel);
37864
+ }
37821
37865
  clearObservedItems() {
37822
37866
  const startPoint = this.getStartPoint();
37823
37867
  const endPoint = this.getEndPoint();
@@ -54453,9 +54497,31 @@ class GravityEngine {
54453
54497
  this.velocities.clear();
54454
54498
  this.lastSyncedPositions.clear();
54455
54499
  }
54500
+ flushSync() {
54501
+ this.syncPositions();
54502
+ }
54503
+ wake() {
54504
+ for (const item of this.board.items.listAll()) {
54505
+ const pos = item.transformation.getTranslation();
54506
+ this.lastSyncedPositions.set(item.getId(), { x: pos.x, y: pos.y });
54507
+ }
54508
+ if (this.tickTimer !== null)
54509
+ return;
54510
+ this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
54511
+ this.syncTimer = setInterval(() => this.syncPositions(), this.SYNC_MS);
54512
+ }
54456
54513
  tick() {
54457
54514
  const dt = this.TICK_MS / 1000;
54458
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54515
+ const draggedIds = this.board.getDraggedItemIds();
54516
+ const items = this.board.items.listAll().filter((item) => {
54517
+ if (item.transformation.isLocked || EXCLUDED_ITEM_TYPES.has(item.itemType))
54518
+ return false;
54519
+ if (draggedIds.has(item.getId()))
54520
+ return false;
54521
+ if (item.parent !== "Board" && draggedIds.has(item.parent))
54522
+ return false;
54523
+ return true;
54524
+ });
54459
54525
  if (items.length < 1)
54460
54526
  return;
54461
54527
  const snap = items.map((item, idx) => {
@@ -54548,7 +54614,16 @@ class GravityEngine {
54548
54614
  }
54549
54615
  }
54550
54616
  syncPositions() {
54551
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54617
+ const draggedIds = this.board.getDraggedItemIds();
54618
+ const items = this.board.items.listAll().filter((item) => {
54619
+ if (item.transformation.isLocked || EXCLUDED_ITEM_TYPES.has(item.itemType))
54620
+ return false;
54621
+ if (draggedIds.has(item.getId()))
54622
+ return false;
54623
+ if (item.parent !== "Board" && draggedIds.has(item.parent))
54624
+ return false;
54625
+ return true;
54626
+ });
54552
54627
  if (items.length === 0)
54553
54628
  return;
54554
54629
  const movedItems = items.map((item) => {
@@ -55974,6 +56049,12 @@ class Board {
55974
56049
  isGravityEnabled() {
55975
56050
  return this.gravity !== null;
55976
56051
  }
56052
+ syncGravity() {
56053
+ this.gravity?.flushSync();
56054
+ }
56055
+ wakeGravity() {
56056
+ this.gravity?.wake();
56057
+ }
55977
56058
  forceGraph = null;
55978
56059
  enableForceGraph(nodeId) {
55979
56060
  if (!this.forceGraph) {
package/dist/cjs/index.js CHANGED
@@ -36852,6 +36852,9 @@ class FloatingPoint extends Point {
36852
36852
  relativePoint;
36853
36853
  pointType = "Floating";
36854
36854
  edge;
36855
+ getEdge() {
36856
+ return this.edge;
36857
+ }
36855
36858
  constructor(item, relativePoint) {
36856
36859
  super();
36857
36860
  this.item = item;
@@ -36893,6 +36896,9 @@ class FixedPoint extends Point {
36893
36896
  relativePoint;
36894
36897
  pointType = "Fixed";
36895
36898
  edge;
36899
+ getEdge() {
36900
+ return this.edge;
36901
+ }
36896
36902
  constructor(item, relativePoint) {
36897
36903
  super();
36898
36904
  this.item = item;
@@ -37806,6 +37812,7 @@ class Connector2 extends BaseItem {
37806
37812
  const point5 = this.startPoint;
37807
37813
  if (point5.pointType !== "Board") {
37808
37814
  point5.recalculatePoint();
37815
+ this.smartJumpStartEdge();
37809
37816
  this.updatePaths();
37810
37817
  this.subject.publish(this);
37811
37818
  }
@@ -37814,10 +37821,47 @@ class Connector2 extends BaseItem {
37814
37821
  const point5 = this.endPoint;
37815
37822
  if (point5.pointType !== "Board") {
37816
37823
  point5.recalculatePoint();
37824
+ this.smartJumpStartEdge();
37817
37825
  this.updatePaths();
37818
37826
  this.subject.publish(this);
37819
37827
  }
37820
37828
  };
37829
+ smartJumpStartEdge() {
37830
+ const start = this.startPoint;
37831
+ if (start.pointType !== "Fixed" && start.pointType !== "Floating")
37832
+ return;
37833
+ const startEdge = start.getEdge();
37834
+ if (!startEdge)
37835
+ return;
37836
+ const item = start.item;
37837
+ const anchors = item.getSnapAnchorPoints?.();
37838
+ if (!anchors || anchors.length === 0)
37839
+ return;
37840
+ const center = item.getMbr().getCenter();
37841
+ const dx = this.endPoint.x - center.x;
37842
+ const dy = this.endPoint.y - center.y;
37843
+ if (dx === 0 && dy === 0)
37844
+ return;
37845
+ let best = anchors[0];
37846
+ let bestDot = -Infinity;
37847
+ for (const anchor of anchors) {
37848
+ const ax = anchor.x - center.x;
37849
+ const ay = anchor.y - center.y;
37850
+ const len = Math.sqrt(ax * ax + ay * ay);
37851
+ if (len === 0)
37852
+ continue;
37853
+ const dot = (ax * dx + ay * dy) / len;
37854
+ if (dot > bestDot) {
37855
+ bestDot = dot;
37856
+ best = anchor;
37857
+ }
37858
+ }
37859
+ const bestRel = toRelativePoint(best, item);
37860
+ const cur = start.relativePoint;
37861
+ if (Math.abs(bestRel.x - cur.x) < 0.5 && Math.abs(bestRel.y - cur.y) < 0.5)
37862
+ return;
37863
+ this.startPoint = new FixedPoint(item, bestRel);
37864
+ }
37821
37865
  clearObservedItems() {
37822
37866
  const startPoint = this.getStartPoint();
37823
37867
  const endPoint = this.getEndPoint();
@@ -54453,9 +54497,31 @@ class GravityEngine {
54453
54497
  this.velocities.clear();
54454
54498
  this.lastSyncedPositions.clear();
54455
54499
  }
54500
+ flushSync() {
54501
+ this.syncPositions();
54502
+ }
54503
+ wake() {
54504
+ for (const item of this.board.items.listAll()) {
54505
+ const pos = item.transformation.getTranslation();
54506
+ this.lastSyncedPositions.set(item.getId(), { x: pos.x, y: pos.y });
54507
+ }
54508
+ if (this.tickTimer !== null)
54509
+ return;
54510
+ this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
54511
+ this.syncTimer = setInterval(() => this.syncPositions(), this.SYNC_MS);
54512
+ }
54456
54513
  tick() {
54457
54514
  const dt = this.TICK_MS / 1000;
54458
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54515
+ const draggedIds = this.board.getDraggedItemIds();
54516
+ const items = this.board.items.listAll().filter((item) => {
54517
+ if (item.transformation.isLocked || EXCLUDED_ITEM_TYPES.has(item.itemType))
54518
+ return false;
54519
+ if (draggedIds.has(item.getId()))
54520
+ return false;
54521
+ if (item.parent !== "Board" && draggedIds.has(item.parent))
54522
+ return false;
54523
+ return true;
54524
+ });
54459
54525
  if (items.length < 1)
54460
54526
  return;
54461
54527
  const snap = items.map((item, idx) => {
@@ -54548,7 +54614,16 @@ class GravityEngine {
54548
54614
  }
54549
54615
  }
54550
54616
  syncPositions() {
54551
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54617
+ const draggedIds = this.board.getDraggedItemIds();
54618
+ const items = this.board.items.listAll().filter((item) => {
54619
+ if (item.transformation.isLocked || EXCLUDED_ITEM_TYPES.has(item.itemType))
54620
+ return false;
54621
+ if (draggedIds.has(item.getId()))
54622
+ return false;
54623
+ if (item.parent !== "Board" && draggedIds.has(item.parent))
54624
+ return false;
54625
+ return true;
54626
+ });
54552
54627
  if (items.length === 0)
54553
54628
  return;
54554
54629
  const movedItems = items.map((item) => {
@@ -55974,6 +56049,12 @@ class Board {
55974
56049
  isGravityEnabled() {
55975
56050
  return this.gravity !== null;
55976
56051
  }
56052
+ syncGravity() {
56053
+ this.gravity?.flushSync();
56054
+ }
56055
+ wakeGravity() {
56056
+ this.gravity?.wake();
56057
+ }
55977
56058
  forceGraph = null;
55978
56059
  enableForceGraph(nodeId) {
55979
56060
  if (!this.forceGraph) {
package/dist/cjs/node.js CHANGED
@@ -39325,6 +39325,9 @@ class FloatingPoint extends Point {
39325
39325
  relativePoint;
39326
39326
  pointType = "Floating";
39327
39327
  edge;
39328
+ getEdge() {
39329
+ return this.edge;
39330
+ }
39328
39331
  constructor(item, relativePoint) {
39329
39332
  super();
39330
39333
  this.item = item;
@@ -39366,6 +39369,9 @@ class FixedPoint extends Point {
39366
39369
  relativePoint;
39367
39370
  pointType = "Fixed";
39368
39371
  edge;
39372
+ getEdge() {
39373
+ return this.edge;
39374
+ }
39369
39375
  constructor(item, relativePoint) {
39370
39376
  super();
39371
39377
  this.item = item;
@@ -40279,6 +40285,7 @@ class Connector2 extends BaseItem {
40279
40285
  const point5 = this.startPoint;
40280
40286
  if (point5.pointType !== "Board") {
40281
40287
  point5.recalculatePoint();
40288
+ this.smartJumpStartEdge();
40282
40289
  this.updatePaths();
40283
40290
  this.subject.publish(this);
40284
40291
  }
@@ -40287,10 +40294,47 @@ class Connector2 extends BaseItem {
40287
40294
  const point5 = this.endPoint;
40288
40295
  if (point5.pointType !== "Board") {
40289
40296
  point5.recalculatePoint();
40297
+ this.smartJumpStartEdge();
40290
40298
  this.updatePaths();
40291
40299
  this.subject.publish(this);
40292
40300
  }
40293
40301
  };
40302
+ smartJumpStartEdge() {
40303
+ const start = this.startPoint;
40304
+ if (start.pointType !== "Fixed" && start.pointType !== "Floating")
40305
+ return;
40306
+ const startEdge = start.getEdge();
40307
+ if (!startEdge)
40308
+ return;
40309
+ const item = start.item;
40310
+ const anchors = item.getSnapAnchorPoints?.();
40311
+ if (!anchors || anchors.length === 0)
40312
+ return;
40313
+ const center = item.getMbr().getCenter();
40314
+ const dx = this.endPoint.x - center.x;
40315
+ const dy = this.endPoint.y - center.y;
40316
+ if (dx === 0 && dy === 0)
40317
+ return;
40318
+ let best = anchors[0];
40319
+ let bestDot = -Infinity;
40320
+ for (const anchor of anchors) {
40321
+ const ax = anchor.x - center.x;
40322
+ const ay = anchor.y - center.y;
40323
+ const len = Math.sqrt(ax * ax + ay * ay);
40324
+ if (len === 0)
40325
+ continue;
40326
+ const dot = (ax * dx + ay * dy) / len;
40327
+ if (dot > bestDot) {
40328
+ bestDot = dot;
40329
+ best = anchor;
40330
+ }
40331
+ }
40332
+ const bestRel = toRelativePoint(best, item);
40333
+ const cur = start.relativePoint;
40334
+ if (Math.abs(bestRel.x - cur.x) < 0.5 && Math.abs(bestRel.y - cur.y) < 0.5)
40335
+ return;
40336
+ this.startPoint = new FixedPoint(item, bestRel);
40337
+ }
40294
40338
  clearObservedItems() {
40295
40339
  const startPoint = this.getStartPoint();
40296
40340
  const endPoint = this.getEndPoint();
@@ -56926,9 +56970,31 @@ class GravityEngine {
56926
56970
  this.velocities.clear();
56927
56971
  this.lastSyncedPositions.clear();
56928
56972
  }
56973
+ flushSync() {
56974
+ this.syncPositions();
56975
+ }
56976
+ wake() {
56977
+ for (const item of this.board.items.listAll()) {
56978
+ const pos = item.transformation.getTranslation();
56979
+ this.lastSyncedPositions.set(item.getId(), { x: pos.x, y: pos.y });
56980
+ }
56981
+ if (this.tickTimer !== null)
56982
+ return;
56983
+ this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
56984
+ this.syncTimer = setInterval(() => this.syncPositions(), this.SYNC_MS);
56985
+ }
56929
56986
  tick() {
56930
56987
  const dt = this.TICK_MS / 1000;
56931
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
56988
+ const draggedIds = this.board.getDraggedItemIds();
56989
+ const items = this.board.items.listAll().filter((item) => {
56990
+ if (item.transformation.isLocked || EXCLUDED_ITEM_TYPES.has(item.itemType))
56991
+ return false;
56992
+ if (draggedIds.has(item.getId()))
56993
+ return false;
56994
+ if (item.parent !== "Board" && draggedIds.has(item.parent))
56995
+ return false;
56996
+ return true;
56997
+ });
56932
56998
  if (items.length < 1)
56933
56999
  return;
56934
57000
  const snap = items.map((item, idx) => {
@@ -57021,7 +57087,16 @@ class GravityEngine {
57021
57087
  }
57022
57088
  }
57023
57089
  syncPositions() {
57024
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
57090
+ const draggedIds = this.board.getDraggedItemIds();
57091
+ const items = this.board.items.listAll().filter((item) => {
57092
+ if (item.transformation.isLocked || EXCLUDED_ITEM_TYPES.has(item.itemType))
57093
+ return false;
57094
+ if (draggedIds.has(item.getId()))
57095
+ return false;
57096
+ if (item.parent !== "Board" && draggedIds.has(item.parent))
57097
+ return false;
57098
+ return true;
57099
+ });
57025
57100
  if (items.length === 0)
57026
57101
  return;
57027
57102
  const movedItems = items.map((item) => {
@@ -58447,6 +58522,12 @@ class Board {
58447
58522
  isGravityEnabled() {
58448
58523
  return this.gravity !== null;
58449
58524
  }
58525
+ syncGravity() {
58526
+ this.gravity?.flushSync();
58527
+ }
58528
+ wakeGravity() {
58529
+ this.gravity?.wake();
58530
+ }
58450
58531
  forceGraph = null;
58451
58532
  enableForceGraph(nodeId) {
58452
58533
  if (!this.forceGraph) {
@@ -36681,6 +36681,9 @@ class FloatingPoint extends Point {
36681
36681
  relativePoint;
36682
36682
  pointType = "Floating";
36683
36683
  edge;
36684
+ getEdge() {
36685
+ return this.edge;
36686
+ }
36684
36687
  constructor(item, relativePoint) {
36685
36688
  super();
36686
36689
  this.item = item;
@@ -36722,6 +36725,9 @@ class FixedPoint extends Point {
36722
36725
  relativePoint;
36723
36726
  pointType = "Fixed";
36724
36727
  edge;
36728
+ getEdge() {
36729
+ return this.edge;
36730
+ }
36725
36731
  constructor(item, relativePoint) {
36726
36732
  super();
36727
36733
  this.item = item;
@@ -37635,6 +37641,7 @@ class Connector2 extends BaseItem {
37635
37641
  const point5 = this.startPoint;
37636
37642
  if (point5.pointType !== "Board") {
37637
37643
  point5.recalculatePoint();
37644
+ this.smartJumpStartEdge();
37638
37645
  this.updatePaths();
37639
37646
  this.subject.publish(this);
37640
37647
  }
@@ -37643,10 +37650,47 @@ class Connector2 extends BaseItem {
37643
37650
  const point5 = this.endPoint;
37644
37651
  if (point5.pointType !== "Board") {
37645
37652
  point5.recalculatePoint();
37653
+ this.smartJumpStartEdge();
37646
37654
  this.updatePaths();
37647
37655
  this.subject.publish(this);
37648
37656
  }
37649
37657
  };
37658
+ smartJumpStartEdge() {
37659
+ const start = this.startPoint;
37660
+ if (start.pointType !== "Fixed" && start.pointType !== "Floating")
37661
+ return;
37662
+ const startEdge = start.getEdge();
37663
+ if (!startEdge)
37664
+ return;
37665
+ const item = start.item;
37666
+ const anchors = item.getSnapAnchorPoints?.();
37667
+ if (!anchors || anchors.length === 0)
37668
+ return;
37669
+ const center = item.getMbr().getCenter();
37670
+ const dx = this.endPoint.x - center.x;
37671
+ const dy = this.endPoint.y - center.y;
37672
+ if (dx === 0 && dy === 0)
37673
+ return;
37674
+ let best = anchors[0];
37675
+ let bestDot = -Infinity;
37676
+ for (const anchor of anchors) {
37677
+ const ax = anchor.x - center.x;
37678
+ const ay = anchor.y - center.y;
37679
+ const len = Math.sqrt(ax * ax + ay * ay);
37680
+ if (len === 0)
37681
+ continue;
37682
+ const dot = (ax * dx + ay * dy) / len;
37683
+ if (dot > bestDot) {
37684
+ bestDot = dot;
37685
+ best = anchor;
37686
+ }
37687
+ }
37688
+ const bestRel = toRelativePoint(best, item);
37689
+ const cur = start.relativePoint;
37690
+ if (Math.abs(bestRel.x - cur.x) < 0.5 && Math.abs(bestRel.y - cur.y) < 0.5)
37691
+ return;
37692
+ this.startPoint = new FixedPoint(item, bestRel);
37693
+ }
37650
37694
  clearObservedItems() {
37651
37695
  const startPoint = this.getStartPoint();
37652
37696
  const endPoint = this.getEndPoint();
@@ -54282,9 +54326,31 @@ class GravityEngine {
54282
54326
  this.velocities.clear();
54283
54327
  this.lastSyncedPositions.clear();
54284
54328
  }
54329
+ flushSync() {
54330
+ this.syncPositions();
54331
+ }
54332
+ wake() {
54333
+ for (const item of this.board.items.listAll()) {
54334
+ const pos = item.transformation.getTranslation();
54335
+ this.lastSyncedPositions.set(item.getId(), { x: pos.x, y: pos.y });
54336
+ }
54337
+ if (this.tickTimer !== null)
54338
+ return;
54339
+ this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
54340
+ this.syncTimer = setInterval(() => this.syncPositions(), this.SYNC_MS);
54341
+ }
54285
54342
  tick() {
54286
54343
  const dt = this.TICK_MS / 1000;
54287
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54344
+ const draggedIds = this.board.getDraggedItemIds();
54345
+ const items = this.board.items.listAll().filter((item) => {
54346
+ if (item.transformation.isLocked || EXCLUDED_ITEM_TYPES.has(item.itemType))
54347
+ return false;
54348
+ if (draggedIds.has(item.getId()))
54349
+ return false;
54350
+ if (item.parent !== "Board" && draggedIds.has(item.parent))
54351
+ return false;
54352
+ return true;
54353
+ });
54288
54354
  if (items.length < 1)
54289
54355
  return;
54290
54356
  const snap = items.map((item, idx) => {
@@ -54377,7 +54443,16 @@ class GravityEngine {
54377
54443
  }
54378
54444
  }
54379
54445
  syncPositions() {
54380
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54446
+ const draggedIds = this.board.getDraggedItemIds();
54447
+ const items = this.board.items.listAll().filter((item) => {
54448
+ if (item.transformation.isLocked || EXCLUDED_ITEM_TYPES.has(item.itemType))
54449
+ return false;
54450
+ if (draggedIds.has(item.getId()))
54451
+ return false;
54452
+ if (item.parent !== "Board" && draggedIds.has(item.parent))
54453
+ return false;
54454
+ return true;
54455
+ });
54381
54456
  if (items.length === 0)
54382
54457
  return;
54383
54458
  const movedItems = items.map((item) => {
@@ -55803,6 +55878,12 @@ class Board {
55803
55878
  isGravityEnabled() {
55804
55879
  return this.gravity !== null;
55805
55880
  }
55881
+ syncGravity() {
55882
+ this.gravity?.flushSync();
55883
+ }
55884
+ wakeGravity() {
55885
+ this.gravity?.wake();
55886
+ }
55806
55887
  forceGraph = null;
55807
55888
  enableForceGraph(nodeId) {
55808
55889
  if (!this.forceGraph) {
package/dist/esm/index.js CHANGED
@@ -36674,6 +36674,9 @@ class FloatingPoint extends Point {
36674
36674
  relativePoint;
36675
36675
  pointType = "Floating";
36676
36676
  edge;
36677
+ getEdge() {
36678
+ return this.edge;
36679
+ }
36677
36680
  constructor(item, relativePoint) {
36678
36681
  super();
36679
36682
  this.item = item;
@@ -36715,6 +36718,9 @@ class FixedPoint extends Point {
36715
36718
  relativePoint;
36716
36719
  pointType = "Fixed";
36717
36720
  edge;
36721
+ getEdge() {
36722
+ return this.edge;
36723
+ }
36718
36724
  constructor(item, relativePoint) {
36719
36725
  super();
36720
36726
  this.item = item;
@@ -37628,6 +37634,7 @@ class Connector2 extends BaseItem {
37628
37634
  const point5 = this.startPoint;
37629
37635
  if (point5.pointType !== "Board") {
37630
37636
  point5.recalculatePoint();
37637
+ this.smartJumpStartEdge();
37631
37638
  this.updatePaths();
37632
37639
  this.subject.publish(this);
37633
37640
  }
@@ -37636,10 +37643,47 @@ class Connector2 extends BaseItem {
37636
37643
  const point5 = this.endPoint;
37637
37644
  if (point5.pointType !== "Board") {
37638
37645
  point5.recalculatePoint();
37646
+ this.smartJumpStartEdge();
37639
37647
  this.updatePaths();
37640
37648
  this.subject.publish(this);
37641
37649
  }
37642
37650
  };
37651
+ smartJumpStartEdge() {
37652
+ const start = this.startPoint;
37653
+ if (start.pointType !== "Fixed" && start.pointType !== "Floating")
37654
+ return;
37655
+ const startEdge = start.getEdge();
37656
+ if (!startEdge)
37657
+ return;
37658
+ const item = start.item;
37659
+ const anchors = item.getSnapAnchorPoints?.();
37660
+ if (!anchors || anchors.length === 0)
37661
+ return;
37662
+ const center = item.getMbr().getCenter();
37663
+ const dx = this.endPoint.x - center.x;
37664
+ const dy = this.endPoint.y - center.y;
37665
+ if (dx === 0 && dy === 0)
37666
+ return;
37667
+ let best = anchors[0];
37668
+ let bestDot = -Infinity;
37669
+ for (const anchor of anchors) {
37670
+ const ax = anchor.x - center.x;
37671
+ const ay = anchor.y - center.y;
37672
+ const len = Math.sqrt(ax * ax + ay * ay);
37673
+ if (len === 0)
37674
+ continue;
37675
+ const dot = (ax * dx + ay * dy) / len;
37676
+ if (dot > bestDot) {
37677
+ bestDot = dot;
37678
+ best = anchor;
37679
+ }
37680
+ }
37681
+ const bestRel = toRelativePoint(best, item);
37682
+ const cur = start.relativePoint;
37683
+ if (Math.abs(bestRel.x - cur.x) < 0.5 && Math.abs(bestRel.y - cur.y) < 0.5)
37684
+ return;
37685
+ this.startPoint = new FixedPoint(item, bestRel);
37686
+ }
37643
37687
  clearObservedItems() {
37644
37688
  const startPoint = this.getStartPoint();
37645
37689
  const endPoint = this.getEndPoint();
@@ -54275,9 +54319,31 @@ class GravityEngine {
54275
54319
  this.velocities.clear();
54276
54320
  this.lastSyncedPositions.clear();
54277
54321
  }
54322
+ flushSync() {
54323
+ this.syncPositions();
54324
+ }
54325
+ wake() {
54326
+ for (const item of this.board.items.listAll()) {
54327
+ const pos = item.transformation.getTranslation();
54328
+ this.lastSyncedPositions.set(item.getId(), { x: pos.x, y: pos.y });
54329
+ }
54330
+ if (this.tickTimer !== null)
54331
+ return;
54332
+ this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
54333
+ this.syncTimer = setInterval(() => this.syncPositions(), this.SYNC_MS);
54334
+ }
54278
54335
  tick() {
54279
54336
  const dt = this.TICK_MS / 1000;
54280
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54337
+ const draggedIds = this.board.getDraggedItemIds();
54338
+ const items = this.board.items.listAll().filter((item) => {
54339
+ if (item.transformation.isLocked || EXCLUDED_ITEM_TYPES.has(item.itemType))
54340
+ return false;
54341
+ if (draggedIds.has(item.getId()))
54342
+ return false;
54343
+ if (item.parent !== "Board" && draggedIds.has(item.parent))
54344
+ return false;
54345
+ return true;
54346
+ });
54281
54347
  if (items.length < 1)
54282
54348
  return;
54283
54349
  const snap = items.map((item, idx) => {
@@ -54370,7 +54436,16 @@ class GravityEngine {
54370
54436
  }
54371
54437
  }
54372
54438
  syncPositions() {
54373
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
54439
+ const draggedIds = this.board.getDraggedItemIds();
54440
+ const items = this.board.items.listAll().filter((item) => {
54441
+ if (item.transformation.isLocked || EXCLUDED_ITEM_TYPES.has(item.itemType))
54442
+ return false;
54443
+ if (draggedIds.has(item.getId()))
54444
+ return false;
54445
+ if (item.parent !== "Board" && draggedIds.has(item.parent))
54446
+ return false;
54447
+ return true;
54448
+ });
54374
54449
  if (items.length === 0)
54375
54450
  return;
54376
54451
  const movedItems = items.map((item) => {
@@ -55796,6 +55871,12 @@ class Board {
55796
55871
  isGravityEnabled() {
55797
55872
  return this.gravity !== null;
55798
55873
  }
55874
+ syncGravity() {
55875
+ this.gravity?.flushSync();
55876
+ }
55877
+ wakeGravity() {
55878
+ this.gravity?.wake();
55879
+ }
55799
55880
  forceGraph = null;
55800
55881
  enableForceGraph(nodeId) {
55801
55882
  if (!this.forceGraph) {
package/dist/esm/node.js CHANGED
@@ -39142,6 +39142,9 @@ class FloatingPoint extends Point {
39142
39142
  relativePoint;
39143
39143
  pointType = "Floating";
39144
39144
  edge;
39145
+ getEdge() {
39146
+ return this.edge;
39147
+ }
39145
39148
  constructor(item, relativePoint) {
39146
39149
  super();
39147
39150
  this.item = item;
@@ -39183,6 +39186,9 @@ class FixedPoint extends Point {
39183
39186
  relativePoint;
39184
39187
  pointType = "Fixed";
39185
39188
  edge;
39189
+ getEdge() {
39190
+ return this.edge;
39191
+ }
39186
39192
  constructor(item, relativePoint) {
39187
39193
  super();
39188
39194
  this.item = item;
@@ -40096,6 +40102,7 @@ class Connector2 extends BaseItem {
40096
40102
  const point5 = this.startPoint;
40097
40103
  if (point5.pointType !== "Board") {
40098
40104
  point5.recalculatePoint();
40105
+ this.smartJumpStartEdge();
40099
40106
  this.updatePaths();
40100
40107
  this.subject.publish(this);
40101
40108
  }
@@ -40104,10 +40111,47 @@ class Connector2 extends BaseItem {
40104
40111
  const point5 = this.endPoint;
40105
40112
  if (point5.pointType !== "Board") {
40106
40113
  point5.recalculatePoint();
40114
+ this.smartJumpStartEdge();
40107
40115
  this.updatePaths();
40108
40116
  this.subject.publish(this);
40109
40117
  }
40110
40118
  };
40119
+ smartJumpStartEdge() {
40120
+ const start = this.startPoint;
40121
+ if (start.pointType !== "Fixed" && start.pointType !== "Floating")
40122
+ return;
40123
+ const startEdge = start.getEdge();
40124
+ if (!startEdge)
40125
+ return;
40126
+ const item = start.item;
40127
+ const anchors = item.getSnapAnchorPoints?.();
40128
+ if (!anchors || anchors.length === 0)
40129
+ return;
40130
+ const center = item.getMbr().getCenter();
40131
+ const dx = this.endPoint.x - center.x;
40132
+ const dy = this.endPoint.y - center.y;
40133
+ if (dx === 0 && dy === 0)
40134
+ return;
40135
+ let best = anchors[0];
40136
+ let bestDot = -Infinity;
40137
+ for (const anchor of anchors) {
40138
+ const ax = anchor.x - center.x;
40139
+ const ay = anchor.y - center.y;
40140
+ const len = Math.sqrt(ax * ax + ay * ay);
40141
+ if (len === 0)
40142
+ continue;
40143
+ const dot = (ax * dx + ay * dy) / len;
40144
+ if (dot > bestDot) {
40145
+ bestDot = dot;
40146
+ best = anchor;
40147
+ }
40148
+ }
40149
+ const bestRel = toRelativePoint(best, item);
40150
+ const cur = start.relativePoint;
40151
+ if (Math.abs(bestRel.x - cur.x) < 0.5 && Math.abs(bestRel.y - cur.y) < 0.5)
40152
+ return;
40153
+ this.startPoint = new FixedPoint(item, bestRel);
40154
+ }
40111
40155
  clearObservedItems() {
40112
40156
  const startPoint = this.getStartPoint();
40113
40157
  const endPoint = this.getEndPoint();
@@ -56743,9 +56787,31 @@ class GravityEngine {
56743
56787
  this.velocities.clear();
56744
56788
  this.lastSyncedPositions.clear();
56745
56789
  }
56790
+ flushSync() {
56791
+ this.syncPositions();
56792
+ }
56793
+ wake() {
56794
+ for (const item of this.board.items.listAll()) {
56795
+ const pos = item.transformation.getTranslation();
56796
+ this.lastSyncedPositions.set(item.getId(), { x: pos.x, y: pos.y });
56797
+ }
56798
+ if (this.tickTimer !== null)
56799
+ return;
56800
+ this.tickTimer = setInterval(() => this.tick(), this.TICK_MS);
56801
+ this.syncTimer = setInterval(() => this.syncPositions(), this.SYNC_MS);
56802
+ }
56746
56803
  tick() {
56747
56804
  const dt = this.TICK_MS / 1000;
56748
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
56805
+ const draggedIds = this.board.getDraggedItemIds();
56806
+ const items = this.board.items.listAll().filter((item) => {
56807
+ if (item.transformation.isLocked || EXCLUDED_ITEM_TYPES.has(item.itemType))
56808
+ return false;
56809
+ if (draggedIds.has(item.getId()))
56810
+ return false;
56811
+ if (item.parent !== "Board" && draggedIds.has(item.parent))
56812
+ return false;
56813
+ return true;
56814
+ });
56749
56815
  if (items.length < 1)
56750
56816
  return;
56751
56817
  const snap = items.map((item, idx) => {
@@ -56838,7 +56904,16 @@ class GravityEngine {
56838
56904
  }
56839
56905
  }
56840
56906
  syncPositions() {
56841
- const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
56907
+ const draggedIds = this.board.getDraggedItemIds();
56908
+ const items = this.board.items.listAll().filter((item) => {
56909
+ if (item.transformation.isLocked || EXCLUDED_ITEM_TYPES.has(item.itemType))
56910
+ return false;
56911
+ if (draggedIds.has(item.getId()))
56912
+ return false;
56913
+ if (item.parent !== "Board" && draggedIds.has(item.parent))
56914
+ return false;
56915
+ return true;
56916
+ });
56842
56917
  if (items.length === 0)
56843
56918
  return;
56844
56919
  const movedItems = items.map((item) => {
@@ -58264,6 +58339,12 @@ class Board {
58264
58339
  isGravityEnabled() {
58265
58340
  return this.gravity !== null;
58266
58341
  }
58342
+ syncGravity() {
58343
+ this.gravity?.flushSync();
58344
+ }
58345
+ wakeGravity() {
58346
+ this.gravity?.wake();
58347
+ }
58267
58348
  forceGraph = null;
58268
58349
  enableForceGraph(nodeId) {
58269
58350
  if (!this.forceGraph) {
@@ -139,6 +139,8 @@ export declare class Board {
139
139
  enableGravity(): void;
140
140
  disableGravity(): void;
141
141
  isGravityEnabled(): boolean;
142
+ syncGravity(): void;
143
+ wakeGravity(): void;
142
144
  private forceGraph;
143
145
  /** Enable force-directed layout for the connected component containing `nodeId`. */
144
146
  enableForceGraph(nodeId: string): void;
@@ -12,6 +12,8 @@ export declare class GravityEngine {
12
12
  constructor(board: Board);
13
13
  start(): void;
14
14
  stop(): void;
15
+ flushSync(): void;
16
+ wake(): void;
15
17
  private tick;
16
18
  private syncPositions;
17
19
  }
@@ -57,6 +57,12 @@ export declare class Connector extends BaseItem {
57
57
  private initText;
58
58
  observerStartPointItem: () => void;
59
59
  observerEndPointItem: () => void;
60
+ /**
61
+ * If the start point is attached to one of the 4 edge-center anchors, re-evaluate
62
+ * which edge best faces the current end position and jump there to avoid sharp bends.
63
+ * Purely local/visual — no operation is emitted.
64
+ */
65
+ private smartJumpStartEdge;
60
66
  clearObservedItems(): void;
61
67
  private unsubscribeFromItem;
62
68
  private subscribeToItem;
@@ -1,6 +1,7 @@
1
1
  import { Point } from "../Point";
2
2
  import { Item } from "../Item";
3
3
  import { Connector } from "./Connector";
4
+ export type Edge = "top" | "bottom" | "left" | "right";
4
5
  export interface BoardPointData {
5
6
  pointType: "Board";
6
7
  x: number;
@@ -35,6 +36,7 @@ export declare class FloatingPoint extends Point {
35
36
  readonly relativePoint: Point;
36
37
  readonly pointType = "Floating";
37
38
  private edge;
39
+ getEdge(): Edge | undefined;
38
40
  constructor(item: Item, relativePoint: Point);
39
41
  recalculatePoint(): void;
40
42
  serialize(): FloatingPointData;
@@ -45,6 +47,7 @@ export declare class FixedPoint extends Point {
45
47
  readonly relativePoint: Point;
46
48
  readonly pointType = "Fixed";
47
49
  private edge;
50
+ getEdge(): Edge | undefined;
48
51
  constructor(item: Item, relativePoint: Point);
49
52
  recalculatePoint(): void;
50
53
  serialize(): FixedPointData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.13.26",
3
+ "version": "0.13.28",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",