Skip to content

Commit 0c5dfdd

Browse files
committed
refactor(core): remove initialized from graph-nodes (#1457)
* refactor(core): remove `initialized` from graph-nodes * chore(changeset): add * refactor(node-resizer): replace node initialized check * chore(changeset): add
1 parent 9a7e4ac commit 0c5dfdd

File tree

9 files changed

+30
-20
lines changed

9 files changed

+30
-20
lines changed

.changeset/breezy-clouds-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": minor
3+
---
4+
5+
Remove `initialized` property from `GraphNode` type

.changeset/tasty-chefs-destroy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/node-resizer": minor
3+
---
4+
5+
Replace node initialized check with dimensions check

packages/core/src/components/Handle/Handle.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const isConnectable = computed(() => {
9797
9898
// todo: remove this and have users handle this themselves using `updateNodeInternals`
9999
// set up handle bounds if they don't exist yet and the node has been initialized (i.e. the handle was added after the node has already been mounted)
100-
until(() => node.initialized)
100+
until(() => !!node.dimensions.width && !!node.dimensions.height)
101101
.toBe(true, { flush: 'post' })
102102
.then(() => {
103103
const existingBounds = node.handleBounds[type.value]?.find((b) => b.id === handleId)

packages/core/src/components/Nodes/NodeWrapper.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ const NodeWrapper = defineComponent({
8484

8585
const isFocusable = toRef(() => (typeof node.focusable === 'undefined' ? nodesFocusable.value : node.focusable))
8686

87+
const isInit = toRef(() => !!node.dimensions.width && !!node.dimensions.height)
88+
8789
const nodeCmp = computed(() => {
8890
const name = node.type || 'default'
8991

@@ -227,7 +229,7 @@ const NodeWrapper = defineComponent({
227229
node.extent === 'parent' ||
228230
(typeof node.extent === 'object' && 'range' in node.extent && node.extent.range === 'parent')
229231
) {
230-
until(() => node.initialized)
232+
until(() => isInit)
231233
.toBe(true)
232234
.then(clampPosition)
233235
}
@@ -260,7 +262,7 @@ const NodeWrapper = defineComponent({
260262
getClass.value,
261263
],
262264
'style': {
263-
visibility: node.initialized ? 'visible' : 'hidden',
265+
visibility: isInit.value ? 'visible' : 'hidden',
264266
zIndex: node.computedPosition.z ?? zIndex.value,
265267
transform: `translate(${node.computedPosition.x}px,${node.computedPosition.y}px)`,
266268
pointerEvents: isSelectable.value || isDraggable.value ? 'all' : 'none',

packages/core/src/store/actions.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { zoomIdentity } from 'd3-zoom'
22
import type { ComputedRef } from 'vue'
3-
import { nextTick } from 'vue'
43
import { until } from '@vueuse/core'
54
import type {
65
Actions,
@@ -163,7 +162,6 @@ export function useActions(
163162
node.dimensions = dimensions
164163
node.handleBounds.source = getHandleBounds('.source', update.nodeElement, nodeBounds, zoom)
165164
node.handleBounds.target = getHandleBounds('.target', update.nodeElement, nodeBounds, zoom)
166-
node.initialized = true
167165

168166
changes[i] = {
169167
id: node.id,
@@ -175,10 +173,8 @@ export function useActions(
175173
}
176174

177175
if (!state.fitViewOnInitDone && state.fitViewOnInit) {
178-
nextTick(() => {
179-
viewportHelper.value.fitView()
180-
state.fitViewOnInitDone = true
181-
})
176+
viewportHelper.value.fitView()
177+
state.fitViewOnInitDone = true
182178
}
183179

184180
if (changes.length) {
@@ -813,7 +809,6 @@ export function useActions(
813809
isParent: _____,
814810
resizing: ______,
815811
dragging: _______,
816-
initialized: ________,
817812
events: _________,
818813
...rest
819814
} = node

packages/core/src/store/getters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export function useGetters(
134134
const initializedNodes: GraphNode[] = []
135135

136136
for (const node of state.nodes) {
137-
if (node.initialized && node.handleBounds !== undefined) {
137+
if (!!node.dimensions.width && !!node.dimensions.height && node.handleBounds !== undefined) {
138138
initializedNodes.push(node)
139139
}
140140
}

packages/core/src/types/node.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ export interface GraphNode<
125125
selected: boolean
126126
resizing: boolean
127127
dragging: boolean
128-
initialized: boolean
129128
data: Data
130129
/** @deprecated will be removed in the next major version */
131130
events: Partial<NodeEventsHandler<CustomEvents>>

packages/core/src/utils/changes.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ export function applyChanges<
183183
const parent = elements[elementIds.indexOf(element.parentNode)]
184184

185185
if (parent && isGraphNode(parent)) {
186-
if (!parent.initialized) {
186+
const parentInit = !!parent.dimensions.width && !!parent.dimensions.height
187+
188+
if (!parentInit) {
187189
nextTick(() => {
188190
handleParentExpand(element, parent)
189191
})
@@ -192,10 +194,6 @@ export function applyChanges<
192194
}
193195
}
194196
}
195-
196-
if (!element.initialized) {
197-
element.initialized = true
198-
}
199197
}
200198
break
201199
}

packages/node-resizer/src/NodeResizer.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts" setup>
2-
import { inject, toRef, watch } from 'vue'
2+
import { computed, inject, toRef, watch } from 'vue'
33
import type { NodeDimensionChange } from '@vue-flow/core'
44
import { NodeIdInjection, useVueFlow } from '@vue-flow/core'
55
import ResizeControl from './ResizeControl.vue'
@@ -22,10 +22,16 @@ const contextNodeId = inject(NodeIdInjection, null)
2222
2323
const nodeId = toRef(() => (typeof props.nodeId === 'string' ? props.nodeId : contextNodeId))
2424
25-
const node = toRef(() => findNode(nodeId.value))
25+
const node = computed(() => findNode(nodeId.value))
2626
2727
watch(
28-
[() => props.minWidth, () => props.minHeight, () => props.maxWidth, () => props.maxHeight, () => node.value?.initialized],
28+
[
29+
() => props.minWidth,
30+
() => props.minHeight,
31+
() => props.maxWidth,
32+
() => props.maxHeight,
33+
() => !!node.value?.dimensions.width && !!node.value.dimensions.height,
34+
],
2935
([minWidth, minHeight, maxWidth, maxHeight, isInitialized]) => {
3036
const n = node.value
3137

0 commit comments

Comments
 (0)