@joint/core 4.0.4 → 4.1.0-beta.1

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.
Files changed (54) hide show
  1. package/README.md +0 -8
  2. package/dist/geometry.js +4962 -6132
  3. package/dist/geometry.min.js +2 -2
  4. package/dist/joint.d.ts +326 -50
  5. package/dist/joint.js +34067 -37565
  6. package/dist/joint.min.js +2 -2
  7. package/dist/joint.nowrap.js +34067 -37565
  8. package/dist/joint.nowrap.min.js +2 -2
  9. package/dist/vectorizer.js +7288 -8907
  10. package/dist/vectorizer.min.js +2 -2
  11. package/dist/version.mjs +1 -1
  12. package/package.json +10 -15
  13. package/src/{linkTools → cellTools}/Button.mjs +8 -6
  14. package/src/{elementTools → cellTools}/Control.mjs +3 -3
  15. package/src/{linkTools → cellTools}/HoverConnect.mjs +1 -1
  16. package/src/dia/Cell.mjs +60 -33
  17. package/src/dia/CellView.mjs +75 -8
  18. package/src/dia/ElementView.mjs +13 -8
  19. package/src/dia/Graph.mjs +148 -40
  20. package/src/dia/HighlighterView.mjs +8 -4
  21. package/src/dia/LinkView.mjs +42 -3
  22. package/src/dia/Paper.mjs +84 -0
  23. package/src/dia/ToolView.mjs +29 -4
  24. package/src/dia/ToolsView.mjs +25 -10
  25. package/src/dia/attributes/connection.mjs +5 -0
  26. package/src/dia/attributes/defs.mjs +3 -0
  27. package/src/dia/attributes/eval.mjs +3 -3
  28. package/src/dia/attributes/index.mjs +3 -0
  29. package/src/dia/attributes/shape.mjs +4 -0
  30. package/src/dia/attributes/text.mjs +15 -5
  31. package/src/dia/ports.mjs +4 -0
  32. package/src/elementTools/HoverConnect.mjs +5 -5
  33. package/src/elementTools/index.mjs +5 -4
  34. package/src/g/rect.mjs +13 -5
  35. package/src/layout/ports/port.mjs +4 -5
  36. package/src/linkTools/Anchor.mjs +1 -1
  37. package/src/linkTools/Arrowhead.mjs +2 -1
  38. package/src/linkTools/RotateLabel.mjs +110 -0
  39. package/src/linkTools/Segments.mjs +1 -1
  40. package/src/linkTools/Vertices.mjs +41 -4
  41. package/src/linkTools/index.mjs +7 -4
  42. package/src/mvc/View.mjs +0 -1
  43. package/src/mvc/ViewBase.mjs +2 -1
  44. package/src/routers/rightAngle.mjs +538 -140
  45. package/src/shapes/standard.mjs +8 -1
  46. package/src/{dia/attributes → util}/calc.mjs +24 -12
  47. package/src/util/index.mjs +1 -0
  48. package/src/util/util.mjs +39 -0
  49. package/src/util/utilHelpers.mjs +2 -1
  50. package/types/geometry.d.ts +6 -1
  51. package/types/joint.d.ts +319 -48
  52. /package/src/{linkTools → cellTools}/Boundary.mjs +0 -0
  53. /package/src/{linkTools → cellTools}/Connect.mjs +0 -0
  54. /package/src/{linkTools → cellTools}/helpers.mjs +0 -0
@@ -0,0 +1,110 @@
1
+ import * as g from '../g/index.mjs';
2
+ import { Control } from '../cellTools/Control.mjs';
3
+
4
+ export const RotateLabel = Control.extend({
5
+
6
+ xAxisVector: new g.Point(1, 0),
7
+
8
+ children() {
9
+ const {
10
+ buttonColor = '#333',
11
+ iconColor = '#fff',
12
+ outlineColor = '#fff'
13
+ } = this.options;
14
+ return [{
15
+ selector: 'handle',
16
+ tagName: 'g',
17
+ attributes: {
18
+ cursor: 'grab',
19
+ },
20
+ children: [{
21
+ tagName: 'circle',
22
+ attributes: {
23
+ r: 10,
24
+ fill: buttonColor,
25
+ stroke: outlineColor,
26
+ },
27
+ }, {
28
+ tagName: 'path',
29
+ attributes: {
30
+ d: 'M -5 0 A 5 5 0 1 1 0 5',
31
+ fill: 'transparent',
32
+ stroke: iconColor,
33
+ strokeWidth: 2,
34
+ strokeLinecap: 'round',
35
+ },
36
+ }, {
37
+ tagName: 'path',
38
+ attributes: {
39
+ d: 'M -3 5 L 0 2.5 0 7.5 Z',
40
+ fill: iconColor,
41
+ stroke: iconColor,
42
+ strokeWidth: 1,
43
+ transform: 'rotate(-5, -3, 5)',
44
+ }
45
+ }]
46
+ }];
47
+ },
48
+
49
+ getPosition(view) {
50
+ const { offset = 0 } = this.options;
51
+ const { x = 0, y = 0 } = typeof offset === 'number' ? { x: 0, y: offset } : offset;
52
+ const label = this.getLabel();
53
+ const labelPosition = this.getLabelPosition(label);
54
+ const coords = view.getLabelCoordinates(labelPosition);
55
+ let { angle = 0, args = {}} = labelPosition;
56
+ const keepGradient = args.keepGradient;
57
+ if (keepGradient) {
58
+ const tangent = view.getTangentAtRatio(
59
+ view.getClosestPointRatio(coords)
60
+ );
61
+ if (tangent) {
62
+ // link slope angle
63
+ angle += tangent.vector().vectorAngle(this.xAxisVector) || 0;
64
+ }
65
+ }
66
+ const matrix = new DOMMatrix()
67
+ .translate(coords.x, coords.y)
68
+ .rotate(angle)
69
+ .translate(x, y);
70
+ return new g.Point(matrix.e, matrix.f);
71
+ },
72
+
73
+ // Override the default `computeVisibility` method to hide the tool if the label is not present.
74
+ computeVisibility() {
75
+ const visibility = Control.prototype.computeVisibility.apply(this, arguments);
76
+ return visibility && !!this.getLabel();
77
+ },
78
+
79
+ setPosition(view, coordinates) {
80
+ const model = view.model;
81
+ const label = this.getLabel();
82
+ if (!label) return;
83
+ const labelPosition = this.getLabelPosition(label);
84
+ const position = view.getLabelCoordinates(labelPosition);
85
+ const angle = 90 - position.theta(coordinates);
86
+ const index = this.getLabelIndex();
87
+ model.prop(['labels', index, 'position', 'angle'], angle);
88
+ },
89
+
90
+ resetPosition(view) {
91
+ const model = view.model;
92
+ const index = this.getLabelIndex();
93
+ model.prop(['labels', index, 'position', 'angle'], 0);
94
+ },
95
+
96
+ getLabelIndex() {
97
+ return this.options.labelIndex || 0;
98
+ },
99
+
100
+ getLabel() {
101
+ return this.relatedView.model.label(this.getLabelIndex()) || null;
102
+ },
103
+
104
+ getLabelPosition(label) {
105
+ const view = this.relatedView;
106
+ const labelPosition = view._normalizeLabelPosition(label.position);
107
+ return view._mergeLabelPositionProperty(labelPosition, view._getDefaultLabelPositionProperty());
108
+ },
109
+
110
+ });
@@ -3,7 +3,7 @@ import V from '../V/index.mjs';
3
3
  import * as util from '../util/index.mjs';
4
4
  import * as mvc from '../mvc/index.mjs';
5
5
  import { ToolView } from '../dia/ToolView.mjs';
6
- import { getAnchor } from './helpers.mjs';
6
+ import { getAnchor } from '../cellTools/helpers.mjs';
7
7
 
8
8
  var SegmentHandle = mvc.View.extend({
9
9
  tagName: 'g',
@@ -65,6 +65,8 @@ export const Vertices = ToolView.extend({
65
65
  snapRadius: 20,
66
66
  redundancyRemoval: true,
67
67
  vertexAdding: true,
68
+ // vertexRemoving: true,
69
+ // vertexMoving: true,
68
70
  stopPropagation: true,
69
71
  scale: null
70
72
  },
@@ -80,19 +82,48 @@ export const Vertices = ToolView.extend({
80
82
  }
81
83
  }],
82
84
  handles: null,
85
+ interactiveLinkNode: null,
83
86
  events: {
84
87
  'mousedown .joint-vertices-path': 'onPathPointerDown',
85
88
  'touchstart .joint-vertices-path': 'onPathPointerDown'
86
89
  },
90
+ linkEvents: {
91
+ mousedown: 'onLinkPointerDown',
92
+ touchstart: 'onLinkPointerDown'
93
+ },
87
94
  onRender: function() {
88
- if (this.options.vertexAdding) {
89
- this.renderChildren();
90
- this.updatePath();
95
+ const { vertexAdding } = this.options;
96
+ if (vertexAdding) {
97
+ const { interactiveLinkNode = null } = vertexAdding;
98
+ if (interactiveLinkNode) {
99
+ this.delegateLinkEvents(interactiveLinkNode);
100
+ } else {
101
+ this.renderChildren();
102
+ this.updatePath();
103
+ }
91
104
  }
92
105
  this.resetHandles();
93
106
  this.renderHandles();
94
107
  return this;
95
108
  },
109
+ delegateLinkEvents: function(selector) {
110
+ this.undelegateLinkEvents();
111
+ const el = this.relatedView.findNode(selector);
112
+ if (!el) {
113
+ console.warn(`Interactive link node "${selector}" not found.`);
114
+ return;
115
+ }
116
+ el.classList.add('joint-vertices-path');
117
+ this.interactiveLinkNode = el;
118
+ this.delegateElementEvents(el, this.linkEvents);
119
+ },
120
+ undelegateLinkEvents: function() {
121
+ const el = this.interactiveLinkNode;
122
+ if (!el) return;
123
+ this.undelegateElementEvents(el);
124
+ el.classList.remove('joint-vertices-path');
125
+ this.interactiveLinkNode = null;
126
+ },
96
127
  update: function() {
97
128
  var relatedView = this.relatedView;
98
129
  var vertices = relatedView.model.vertices();
@@ -146,7 +177,8 @@ export const Vertices = ToolView.extend({
146
177
  }
147
178
  },
148
179
  updatePath: function() {
149
- var connection = this.childNodes.connection;
180
+ if (this.interactiveLinkNode) return;
181
+ const connection = this.childNodes.connection;
150
182
  if (connection) connection.setAttribute('d', this.relatedView.getSerializedConnection());
151
183
  },
152
184
  startHandleListening: function(handle) {
@@ -245,8 +277,13 @@ export const Vertices = ToolView.extend({
245
277
  this.eventData(normalizedEvent, { vertexAdded: true });
246
278
  handle.onPointerDown(normalizedEvent);
247
279
  },
280
+ onLinkPointerDown: function(evt) {
281
+ this.relatedView.preventDefaultInteraction(evt);
282
+ this.onPathPointerDown(evt);
283
+ },
248
284
  onRemove: function() {
249
285
  this.resetHandles();
286
+ this.undelegateLinkEvents();
250
287
  }
251
288
  }, {
252
289
  VertexHandle: VertexHandle // keep as class property
@@ -1,8 +1,11 @@
1
1
  export * from './Vertices.mjs';
2
2
  export * from './Segments.mjs';
3
3
  export * from './Arrowhead.mjs';
4
- export * from './Boundary.mjs';
5
4
  export * from './Anchor.mjs';
6
- export * from './Button.mjs';
7
- export * from './Connect.mjs';
8
- export * from './HoverConnect.mjs';
5
+ export * from './RotateLabel.mjs';
6
+
7
+ export * from '../cellTools/Button.mjs';
8
+ export * from '../cellTools/Boundary.mjs';
9
+ export * from '../cellTools/Connect.mjs';
10
+ export * from '../cellTools/HoverConnect.mjs';
11
+ export * from '../cellTools/Control.mjs';
package/src/mvc/View.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import $ from './Dom/index.mjs';
2
-
3
2
  import * as util from '../util/index.mjs';
4
3
  import V from '../V/index.mjs';
5
4
  import { ViewBase } from './ViewBase.mjs';
@@ -35,7 +35,8 @@ export var ViewBase = function(options) {
35
35
  var delegateEventSplitter = /^(\S+)\s*(.*)$/;
36
36
 
37
37
  // List of view options to be set as properties.
38
- var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events'];
38
+ // TODO: `style` attribute is not supported in ViewBase class yet, but only in View class that extends ViewBase.
39
+ var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events', 'style'];
39
40
 
40
41
  // Set up all inheritable **ViewBase** properties and methods.
41
42
  assign(ViewBase.prototype, Events, {