Browse Source

add position to payload and update on dragging nodes

pull/1/head
Stephanie Gredell 7 months ago
parent
commit
8533cf3ca8
  1. 13
      static/app.js
  2. 3
      static/connection.js
  3. 9
      static/node.js

13
static/app.js

@ -74,7 +74,10 @@ export class CanvasApp {
const svgP = pt.matrixTransform(this.canvas.getScreenCTM().inverse()); const svgP = pt.matrixTransform(this.canvas.getScreenCTM().inverse());
const x = svgP.x - this.componentSize.width / 2; const x = svgP.x - this.componentSize.width / 2;
const y = svgP.y - this.componentSize.height / 2; const y = svgP.y - this.componentSize.height / 2;
new ComponentNode(type, x, y, this); const node = new ComponentNode(type, x, y, this);
node.x = x;
node.y = y;
this.placedComponents.push(node)
if (this.placeholderText) { if (this.placeholderText) {
this.placeholderText.remove(); this.placeholderText.remove();
this.placeholderText = null; this.placeholderText = null;
@ -220,9 +223,11 @@ export class CanvasApp {
const nodes = this.placedComponents.map(n => ({ const nodes = this.placedComponents.map(n => ({
id: n.id, id: n.id,
type: n.type, type: n.type,
x: n.x, props: n.props,
y: n.y, position: {
props: n.props x: n.x,
y: n.y
}
})); }));
const connections = this.connections.map(c => ({ const connections = this.connections.map(c => ({

3
static/connection.js

@ -11,7 +11,7 @@ export class Connection {
stroke: '#ccc', 'stroke-width': 2, 'marker-end': 'url(#arrowhead)' stroke: '#ccc', 'stroke-width': 2, 'marker-end': 'url(#arrowhead)'
}); });
this.hitbox = createSVGElement('circle', { this.hitbox = createSVGElement('circle', {
r: 8, r: 12,
fill: 'transparent', fill: 'transparent',
cursor: 'pointer', cursor: 'pointer',
}); });
@ -82,7 +82,6 @@ export class Connection {
} }
toggleDirection() { toggleDirection() {
console.log('toggle direction')
const order = ['forward', 'backward', 'bidirectional']; const order = ['forward', 'backward', 'bidirectional'];
const currentIndex = order.indexOf(this.direction); const currentIndex = order.indexOf(this.direction);
const nextIndex = (currentIndex + 1) % order.length; const nextIndex = (currentIndex + 1) % order.length;

9
static/node.js

@ -74,11 +74,10 @@ export class ComponentNode {
this.group.setAttribute('transform', `translate(${newX}, ${newY})`); this.group.setAttribute('transform', `translate(${newX}, ${newY})`);
this.app.connections.forEach(conn => { this.x = newX;
if (conn.start === this || conn.end === this) { this.y = newY;
conn.updatePosition();
} this.app.updateConnectionFor(this);
});
}; };
const onMouseUp = () => { const onMouseUp = () => {

Loading…
Cancel
Save