This commit is contained in:
trading_peter 2024-12-20 14:05:35 +01:00
parent 48fd8fef73
commit 6d77ff13c9
2 changed files with 18 additions and 4 deletions

View File

@ -185,4 +185,15 @@ export class TpFlowNode extends LitElement {
this.style.transform = `translate(${data.position.x}px, ${data.position.y}px)`;
}
}
dispatchDataUpdate() {
this.dispatchEvent(new CustomEvent('flow-changed', {
detail: {
type: 'node-data-changed',
data: this.exportData()
},
bubbles: true,
composed: true
}));
}
}

View File

@ -163,12 +163,16 @@ export class TpFlowNodes extends zoom(panning(connections(LitElement))) {
}
}
// Adjust position for current canvas translation and scale
const adjustedX = (x - this.currentX) / this.scale;
const adjustedY = (y - this.currentY) / this.scale;
const node = new NodeClass();
node.setAttribute('part', 'node');
node.setAttribute('exportparts', 'node-content');
node.importData({
id: `node_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`,
position: { x, y },
position: { x: adjustedX, y: adjustedY },
data: initialData
});
@ -231,9 +235,8 @@ export class TpFlowNodes extends zoom(panning(connections(LitElement))) {
_dispatchChangeEvent(detail = {}) {
this.dispatchEvent(new CustomEvent('flow-changed', {
detail: {
type: detail.type, // Type of change: 'node-added', 'node-removed', 'node-moved', 'connection-added', etc.
data: detail.data, // Additional data specific to the change
flow: this.exportFlow() // Current state of the entire flow
type: detail.type, // Type of change: 'node-added', 'node-removed', 'node-moved', 'connection-added', 'node-data-changed'.
data: detail.data,
},
bubbles: true,
composed: true