@metadev/daga 4.2.5 → 4.2.6

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/Changelog.md CHANGED
@@ -6,6 +6,12 @@ List of releases and changes.
6
6
 
7
7
  ## Next release Joyeuse
8
8
 
9
+ ## v. 4.2.6
10
+
11
+ - Fix bug where editing a property with a root attribute fails in React [#323](https://github.com/metadevpro/daga/pull/323)
12
+ - Fix bug where nodes dragged from the palette are off center in React [#324](https://github.com/metadevpro/daga/pull/324)
13
+ - Adjust connection label locations [#326](https://github.com/metadevpro/daga/pull/326)
14
+
9
15
  ## v. 4.2.5
10
16
 
11
17
  - Add methods `getZoomLevel()` and `getViewCoordinates()` in `canvas` to obtain the current zoom and pan level of the view [#317](https://github.com/metadevpro/daga/pull/317)
package/index.cjs.js CHANGED
@@ -5,20 +5,20 @@ var rxjs = require('rxjs');
5
5
  var uuid = require('uuid');
6
6
 
7
7
  function _interopNamespaceDefault(e) {
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
16
18
  });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
22
  }
23
23
 
24
24
  var d3__namespace = /*#__PURE__*/_interopNamespaceDefault(d3);
@@ -1479,6 +1479,9 @@ class ValueSet {
1479
1479
  * @returns The value if it could be found, `undefined` if nothing could be found.
1480
1480
  */
1481
1481
  getRootElementValue(rootAttribute) {
1482
+ if (!this.rootElement) {
1483
+ return;
1484
+ }
1482
1485
  if (typeof rootAttribute === 'string') {
1483
1486
  return this.rootElement[rootAttribute];
1484
1487
  }
@@ -1505,6 +1508,9 @@ class ValueSet {
1505
1508
  * @param value The value to set the root element's attribute to.
1506
1509
  */
1507
1510
  setRootElementValue(rootAttribute, value) {
1511
+ if (!this.rootElement) {
1512
+ return;
1513
+ }
1508
1514
  if (typeof rootAttribute === 'string') {
1509
1515
  this.rootElement[rootAttribute] = value;
1510
1516
  }
@@ -8383,63 +8389,60 @@ class DiagramCanvas {
8383
8389
  const deltaY = connection.endCoords[1] - connection.startCoords[1];
8384
8390
  switch (connection.startDirection) {
8385
8391
  case exports.Side.Top:
8386
- startLabelShiftX = deltaX >= 0 ? 1 : -1;
8387
- middleLabelShiftX = startLabelShiftX;
8392
+ startLabelShiftX = deltaX >= 0 ? -0.5 : 0.5;
8388
8393
  endLabelShiftX = startLabelShiftX;
8389
- startLabelShiftY = -1;
8394
+ startLabelShiftY = -0.5;
8390
8395
  break;
8391
8396
  case exports.Side.Bottom:
8392
- startLabelShiftX = deltaX >= 0 ? 1 : -1;
8393
- middleLabelShiftX = startLabelShiftX;
8397
+ startLabelShiftX = deltaX >= 0 ? -0.5 : 0.5;
8394
8398
  endLabelShiftX = startLabelShiftX;
8395
- startLabelShiftY = 1;
8399
+ startLabelShiftY = 0.5;
8396
8400
  break;
8397
8401
  case exports.Side.Left:
8398
- startLabelShiftX = -1;
8399
- startLabelShiftY = deltaY > 0 ? 1 : -1;
8400
- middleLabelShiftY = startLabelShiftY;
8402
+ startLabelShiftX = -0.5;
8403
+ startLabelShiftY = deltaY > 0 ? -0.5 : 0.5;
8401
8404
  endLabelShiftY = startLabelShiftY;
8402
8405
  break;
8403
8406
  case exports.Side.Right:
8404
- startLabelShiftX = 1;
8405
- startLabelShiftY = deltaY > 0 ? 1 : -1;
8406
- middleLabelShiftY = startLabelShiftY;
8407
+ startLabelShiftX = 0.5;
8408
+ startLabelShiftY = deltaY > 0 ? -0.5 : 0.5;
8407
8409
  endLabelShiftY = startLabelShiftY;
8408
8410
  break;
8409
8411
  default:
8410
- startLabelShiftX = 1;
8411
- middleLabelShiftX = startLabelShiftX;
8412
+ startLabelShiftX = 0.5;
8412
8413
  endLabelShiftX = startLabelShiftX;
8413
- startLabelShiftY = -1;
8414
- middleLabelShiftY = startLabelShiftY;
8414
+ startLabelShiftY = -0.5;
8415
8415
  endLabelShiftY = startLabelShiftY;
8416
8416
  }
8417
8417
  switch (connection.endDirection) {
8418
8418
  case exports.Side.Top:
8419
- endLabelShiftX = deltaX >= 0 ? 1 : -1;
8420
- middleLabelShiftX = endLabelShiftX;
8421
- endLabelShiftY = 1;
8419
+ endLabelShiftX = deltaX >= 0 ? 0.5 : -0.5;
8420
+ endLabelShiftY = 0.5;
8422
8421
  break;
8423
8422
  case exports.Side.Bottom:
8424
- endLabelShiftX = deltaX >= 0 ? 1 : -1;
8425
- middleLabelShiftX = endLabelShiftX;
8426
- endLabelShiftY = -1;
8423
+ endLabelShiftX = deltaX >= 0 ? 0.5 : -0.5;
8424
+ endLabelShiftY = -0.5;
8427
8425
  break;
8428
8426
  case exports.Side.Left:
8429
- endLabelShiftX = -1;
8430
- endLabelShiftY = deltaY > 0 ? 1 : -1;
8431
- middleLabelShiftY = endLabelShiftY;
8427
+ endLabelShiftX = -0.5;
8428
+ endLabelShiftY = deltaY > 0 ? 0.5 : -0.5;
8432
8429
  break;
8433
8430
  case exports.Side.Right:
8434
- endLabelShiftX = 1;
8435
- endLabelShiftY = deltaY > 0 ? 1 : -1;
8436
- middleLabelShiftY = endLabelShiftY;
8431
+ endLabelShiftX = 0.5;
8432
+ endLabelShiftY = deltaY > 0 ? 0.5 : -0.5;
8437
8433
  break;
8438
8434
  default:
8439
- endLabelShiftX = 1;
8440
- middleLabelShiftX = endLabelShiftX;
8441
- endLabelShiftY = -1;
8442
- middleLabelShiftY = endLabelShiftY;
8435
+ endLabelShiftX = 0.5;
8436
+ endLabelShiftY = -0.5;
8437
+ }
8438
+ if (Math.abs(deltaX) >= Math.abs(deltaY)) {
8439
+ // horizontal quadrant
8440
+ middleLabelShiftX = deltaX > 0 ? -0.5 : 0.5;
8441
+ middleLabelShiftY = deltaY > 0 ? 0.5 : -0.5;
8442
+ } else {
8443
+ // vertical quadrant
8444
+ middleLabelShiftX = deltaX > 0 ? 0.5 : -0.5;
8445
+ middleLabelShiftY = deltaY > 0 ? -0.5 : 0.5;
8443
8446
  }
8444
8447
  }
8445
8448
  // bind start labels
package/index.esm.js CHANGED
@@ -1458,6 +1458,9 @@ class ValueSet {
1458
1458
  * @returns The value if it could be found, `undefined` if nothing could be found.
1459
1459
  */
1460
1460
  getRootElementValue(rootAttribute) {
1461
+ if (!this.rootElement) {
1462
+ return;
1463
+ }
1461
1464
  if (typeof rootAttribute === 'string') {
1462
1465
  return this.rootElement[rootAttribute];
1463
1466
  }
@@ -1484,6 +1487,9 @@ class ValueSet {
1484
1487
  * @param value The value to set the root element's attribute to.
1485
1488
  */
1486
1489
  setRootElementValue(rootAttribute, value) {
1490
+ if (!this.rootElement) {
1491
+ return;
1492
+ }
1487
1493
  if (typeof rootAttribute === 'string') {
1488
1494
  this.rootElement[rootAttribute] = value;
1489
1495
  }
@@ -8362,63 +8368,60 @@ class DiagramCanvas {
8362
8368
  const deltaY = connection.endCoords[1] - connection.startCoords[1];
8363
8369
  switch (connection.startDirection) {
8364
8370
  case Side.Top:
8365
- startLabelShiftX = deltaX >= 0 ? 1 : -1;
8366
- middleLabelShiftX = startLabelShiftX;
8371
+ startLabelShiftX = deltaX >= 0 ? -0.5 : 0.5;
8367
8372
  endLabelShiftX = startLabelShiftX;
8368
- startLabelShiftY = -1;
8373
+ startLabelShiftY = -0.5;
8369
8374
  break;
8370
8375
  case Side.Bottom:
8371
- startLabelShiftX = deltaX >= 0 ? 1 : -1;
8372
- middleLabelShiftX = startLabelShiftX;
8376
+ startLabelShiftX = deltaX >= 0 ? -0.5 : 0.5;
8373
8377
  endLabelShiftX = startLabelShiftX;
8374
- startLabelShiftY = 1;
8378
+ startLabelShiftY = 0.5;
8375
8379
  break;
8376
8380
  case Side.Left:
8377
- startLabelShiftX = -1;
8378
- startLabelShiftY = deltaY > 0 ? 1 : -1;
8379
- middleLabelShiftY = startLabelShiftY;
8381
+ startLabelShiftX = -0.5;
8382
+ startLabelShiftY = deltaY > 0 ? -0.5 : 0.5;
8380
8383
  endLabelShiftY = startLabelShiftY;
8381
8384
  break;
8382
8385
  case Side.Right:
8383
- startLabelShiftX = 1;
8384
- startLabelShiftY = deltaY > 0 ? 1 : -1;
8385
- middleLabelShiftY = startLabelShiftY;
8386
+ startLabelShiftX = 0.5;
8387
+ startLabelShiftY = deltaY > 0 ? -0.5 : 0.5;
8386
8388
  endLabelShiftY = startLabelShiftY;
8387
8389
  break;
8388
8390
  default:
8389
- startLabelShiftX = 1;
8390
- middleLabelShiftX = startLabelShiftX;
8391
+ startLabelShiftX = 0.5;
8391
8392
  endLabelShiftX = startLabelShiftX;
8392
- startLabelShiftY = -1;
8393
- middleLabelShiftY = startLabelShiftY;
8393
+ startLabelShiftY = -0.5;
8394
8394
  endLabelShiftY = startLabelShiftY;
8395
8395
  }
8396
8396
  switch (connection.endDirection) {
8397
8397
  case Side.Top:
8398
- endLabelShiftX = deltaX >= 0 ? 1 : -1;
8399
- middleLabelShiftX = endLabelShiftX;
8400
- endLabelShiftY = 1;
8398
+ endLabelShiftX = deltaX >= 0 ? 0.5 : -0.5;
8399
+ endLabelShiftY = 0.5;
8401
8400
  break;
8402
8401
  case Side.Bottom:
8403
- endLabelShiftX = deltaX >= 0 ? 1 : -1;
8404
- middleLabelShiftX = endLabelShiftX;
8405
- endLabelShiftY = -1;
8402
+ endLabelShiftX = deltaX >= 0 ? 0.5 : -0.5;
8403
+ endLabelShiftY = -0.5;
8406
8404
  break;
8407
8405
  case Side.Left:
8408
- endLabelShiftX = -1;
8409
- endLabelShiftY = deltaY > 0 ? 1 : -1;
8410
- middleLabelShiftY = endLabelShiftY;
8406
+ endLabelShiftX = -0.5;
8407
+ endLabelShiftY = deltaY > 0 ? 0.5 : -0.5;
8411
8408
  break;
8412
8409
  case Side.Right:
8413
- endLabelShiftX = 1;
8414
- endLabelShiftY = deltaY > 0 ? 1 : -1;
8415
- middleLabelShiftY = endLabelShiftY;
8410
+ endLabelShiftX = 0.5;
8411
+ endLabelShiftY = deltaY > 0 ? 0.5 : -0.5;
8416
8412
  break;
8417
8413
  default:
8418
- endLabelShiftX = 1;
8419
- middleLabelShiftX = endLabelShiftX;
8420
- endLabelShiftY = -1;
8421
- middleLabelShiftY = endLabelShiftY;
8414
+ endLabelShiftX = 0.5;
8415
+ endLabelShiftY = -0.5;
8416
+ }
8417
+ if (Math.abs(deltaX) >= Math.abs(deltaY)) {
8418
+ // horizontal quadrant
8419
+ middleLabelShiftX = deltaX > 0 ? -0.5 : 0.5;
8420
+ middleLabelShiftY = deltaY > 0 ? 0.5 : -0.5;
8421
+ } else {
8422
+ // vertical quadrant
8423
+ middleLabelShiftX = deltaX > 0 ? 0.5 : -0.5;
8424
+ middleLabelShiftY = deltaY > 0 ? -0.5 : 0.5;
8422
8425
  }
8423
8426
  }
8424
8427
  // bind start labels
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metadev/daga",
3
- "version": "4.2.5",
3
+ "version": "4.2.6",
4
4
  "dependencies": {},
5
5
  "peerDependencies": {
6
6
  "d3": "^7.9.0",