diff --git a/connections.js b/connections.js index 29f33e1..6abcfff 100644 --- a/connections.js +++ b/connections.js @@ -283,6 +283,9 @@ export const connections = function(superClass) { const path = `M${start.x},${start.y} C${controlPoint1.x},${controlPoint1.y} ${controlPoint2.x},${controlPoint2.y} ${end.x},${end.y}`; const isSelected = this.selectedConnection === conn.id; + // Get label position at midpoint of curve + const labelPoint = getPointOnCurve(0.5); + return svg` + ${conn.label ? svg` + ${conn.label} + ` : ''} ${isSelected ? svg` @@ -329,6 +342,8 @@ export const connections = function(superClass) { } _handleConnectionClick(connectionId) { + if (this.readonly) return; + // Deselect if clicking the same connection if (this.selectedConnection === connectionId) { this.selectedConnection = null; @@ -354,6 +369,8 @@ export const connections = function(superClass) { } _handlePortClick(e) { + if (this.readonly) return; + const { node, port } = e.detail; const nodeId = node.id; const { portType, portId, portName } = port; diff --git a/package.json b/package.json index 59e2fce..147d785 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tp/tp-flow-nodes", - "version": "1.2.1", + "version": "1.3.0", "description": "", "main": "tp-flow-nodes.js", "scripts": { diff --git a/tp-flow-node.js b/tp-flow-node.js index 8c95663..6485b57 100644 --- a/tp-flow-node.js +++ b/tp-flow-node.js @@ -106,7 +106,7 @@ export class TpFlowNode extends LitElement { return html`
A Node -
+ ${!this.readonly ? html`
` : null}
`; } @@ -122,7 +122,8 @@ export class TpFlowNode extends LitElement { outputs: { type: Array }, x: { type: Number }, y: { type: Number }, - data: { type: Object } + data: { type: Object }, + readonly: { type: Boolean, reflect: true } }; } @@ -133,6 +134,7 @@ export class TpFlowNode extends LitElement { this.x = 0; this.y = 0; this.data = {}; + this.readonly = false; } updated(changes) { diff --git a/tp-flow-nodes.js b/tp-flow-nodes.js index 4c996a9..e14ddd7 100644 --- a/tp-flow-nodes.js +++ b/tp-flow-nodes.js @@ -41,7 +41,7 @@ export class TpFlowNodes extends zoom(panning(connections(LitElement))) { render() { return html`
- ${repeat(this.nodes, node => node.id, node => html`${node}`)} + ${repeat(this.nodes, node => node.id, node => { node.readonly = this.readonly; return html`${node}`; })} ${this._renderConnections()}
`; @@ -50,13 +50,15 @@ export class TpFlowNodes extends zoom(panning(connections(LitElement))) { static get properties() { return { nodes: { type: Array }, - connections: { type: Array } + connections: { type: Array }, + readonly: { type: Boolean, reflect: true } }; } constructor() { super(); this.nodes = []; + this.readonly = false; this._boundDeleteHandler = this._handleNodeDeleteRequested.bind(this); } @@ -74,6 +76,8 @@ export class TpFlowNodes extends zoom(panning(connections(LitElement))) { } _handleNodeDeleteRequested(e) { + if (this.readonly) return; + const { nodeId } = e.detail; this.removeNode(nodeId); }