From 61294b175ff020508ff65ea887a0957f0d22521a Mon Sep 17 00:00:00 2001 From: Robert Duncan Date: Mon, 21 Oct 2024 21:10:56 -0400 Subject: [PATCH 1/4] wip: add edge create, remove --- node_editor/src/components/NodeEditor.vue | 34 +++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/node_editor/src/components/NodeEditor.vue b/node_editor/src/components/NodeEditor.vue index 1a867df8..84988cb6 100644 --- a/node_editor/src/components/NodeEditor.vue +++ b/node_editor/src/components/NodeEditor.vue @@ -28,6 +28,7 @@ :fit-view-on-init="true" v-model="vueFlowElements" @wheel.prevent="onWheel"> + @connect="onConnect" @@ -39,7 +40,7 @@ diff --git a/node_editor/src/components/NodeEditor.vue b/node_editor/src/components/NodeEditor.vue index 84988cb6..e909bbc2 100644 --- a/node_editor/src/components/NodeEditor.vue +++ b/node_editor/src/components/NodeEditor.vue @@ -28,7 +28,6 @@ :fit-view-on-init="true" v-model="vueFlowElements" @wheel.prevent="onWheel"> - @connect="onConnect" diff --git a/node_editor/src/components/StateEditor.vue b/node_editor/src/components/StateEditor.vue index ba7c9575..c29e4655 100644 --- a/node_editor/src/components/StateEditor.vue +++ b/node_editor/src/components/StateEditor.vue @@ -40,31 +40,26 @@ const elements = computed({ } stateHash[key] = el + } + for (const [key, value] of Object.entries(states.value)) { if (value.on) { for (const [edgeKey, edgeValue] of Object.entries(value.on)) { - if (Array.isArray(edgeValue)) { - for (const edge of edgeValue) { - // TODO: handle typescript errors for both types of states - // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access - const edgeJson = edge.toJSON() - // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access - const target = edgeJson.target.toString() - stateElements.push({ - id: `${key}-${edgeKey}`, - target: target, - source: key, - label: edgeKey, - animated: true, - }) - - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - hasInputs[target] = true - } - } + const target = edgeValue.target || edgeValue + // TODO: handle typescript errors for both types of states + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access + stateElements.push({ + id: `${key}-${target}`, + source: key, + target: target, + label: edgeKey, + animated: true, + }) + + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + hasInputs[target] = true } } - index++ } @@ -78,6 +73,7 @@ const elements = computed({ return stateElements }, + set: newValue => { // update modelValue when elements change onElementsChange(newValue) @@ -85,7 +81,6 @@ const elements = computed({ // TODO: emit('update:modelValue', modelValue) }, }) - const onElementsChange = (elements: FlowElements) => { const edges: Record> = {} const idToLabel: Record = {} @@ -104,19 +99,18 @@ const onElementsChange = (elements: FlowElements) => { states[label] = { type: 'final', } - } /* else if (el.source && el.target) { + } else if (el.source && el.target) { // it's an edge edges[el.source] = edges[el.source] || {} edges[el.source][label] = { target: el.target, } - } */ else { + } else { // it's a state states[label] = { on: {}, } } - idToLabel[el.id] = label } From 86dce42529bcafd222aa7b743e60cfa261c4f77f Mon Sep 17 00:00:00 2001 From: Robert Duncan Date: Sun, 3 Nov 2024 12:18:24 -0500 Subject: [PATCH 4/4] chore: update change log, add comment --- .../node-editor/168_edge_connections_2024-10-22-01-17.json | 2 +- node_editor/src/components/StateEditor.vue | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/common/changes/@stonecrop/node-editor/168_edge_connections_2024-10-22-01-17.json b/common/changes/@stonecrop/node-editor/168_edge_connections_2024-10-22-01-17.json index 970a1a3f..ad91f918 100644 --- a/common/changes/@stonecrop/node-editor/168_edge_connections_2024-10-22-01-17.json +++ b/common/changes/@stonecrop/node-editor/168_edge_connections_2024-10-22-01-17.json @@ -3,7 +3,7 @@ { "packageName": "@stonecrop/node-editor", "comment": "Add handling for edge creation and removal.", - "type": "none" + "type": "patch" } ], "packageName": "@stonecrop/node-editor" diff --git a/node_editor/src/components/StateEditor.vue b/node_editor/src/components/StateEditor.vue index c29e4655..da868f6f 100644 --- a/node_editor/src/components/StateEditor.vue +++ b/node_editor/src/components/StateEditor.vue @@ -45,6 +45,8 @@ const elements = computed({ for (const [key, value] of Object.entries(states.value)) { if (value.on) { for (const [edgeKey, edgeValue] of Object.entries(value.on)) { + // If the proxy array 'value.on' has more than one edge, 'edgeValue' will contain a proxy object + // where 'target' can be accessed. Otherwise, 'edgeValue' will be available directly. const target = edgeValue.target || edgeValue // TODO: handle typescript errors for both types of states // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access