Skip to content

AI-native design editor. Open-source Figma alternative.

fix(vue): guard optional resize test state without lint noise

Danila Poyarkov17f791ffe44f
diff --git a/packages/vue/src/shared/input/resize.ts b/packages/vue/src/shared/input/resize.ts
index 75974fb1a..76533a7ec 100644
--- a/packages/vue/src/shared/input/resize.ts
+++ b/packages/vue/src/shared/input/resize.ts
@@ -16,6 +16,7 @@ import {
import { calculateResizeRect } from '#vue/shared/input/resize/rect'
import { applyResizeSnap } from '#vue/shared/input/resize/snap'
+import { optionalEditorState } from '#vue/shared/input/snap'
import type { DragResize } from '#vue/shared/input/types'
/**
@@ -228,7 +229,7 @@ function clearResizedRawGeometry(editor: Editor, nodeId: string): void {
export function commitResizePreview(dragState: DragResize, editor: Editor) {
// See applyResize — reactive drag state must not leak into graph writes.
const d = toRaw(dragState)
- editor.state.snapGuides = []
+ optionalEditorState(editor)?.snapGuides.splice(0)
const node = editor.graph.getNode(d.nodeId)
if (!node) return
const finalChanges = snapshotResizeFinal(node)
diff --git a/packages/vue/src/shared/input/resize/snap.ts b/packages/vue/src/shared/input/resize/snap.ts
index 779a1b5a1..21dabe726 100644
--- a/packages/vue/src/shared/input/resize/snap.ts
+++ b/packages/vue/src/shared/input/resize/snap.ts
@@ -5,6 +5,7 @@ import type { Rect } from '@open-pencil/scene-graph/primitives'
import { explicitSnapTargets } from '#vue/shared/input/explicit-snap-targets'
import {
+ optionalEditorState,
resolveObjectPixelSnap,
worldBoundsNode,
worldDeltaToParentLocal
@@ -79,8 +80,9 @@ export function applyResizeSnap(
editor: Editor,
disableSnapping: boolean
): Rect {
- if (disableSnapping || !editor.state) {
- if (editor.state) editor.state.snapGuides = []
+ const state = optionalEditorState(editor)
+ if (disableSnapping || !state) {
+ if (state) state.snapGuides = []
return rect
}
@@ -108,6 +110,6 @@ export function applyResizeSnap(
const dx = horizontal ? localCorrection.x : 0
const dy = vertical ? localCorrection.y : 0
- editor.state.snapGuides = snap.guides
+ state.snapGuides = snap.guides
return applyEdgeDelta(drag.handle, rect, dx, dy)
}
diff --git a/packages/vue/src/shared/input/snap.ts b/packages/vue/src/shared/input/snap.ts
index a257b9984..7b65c71e0 100644
--- a/packages/vue/src/shared/input/snap.ts
+++ b/packages/vue/src/shared/input/snap.ts
@@ -197,6 +197,12 @@ export function worldDeltaToParentLocal(
return { x: endpoint.x - origin.x, y: endpoint.y - origin.y }
}
+type EditorWithOptionalState = Omit<Editor, 'state'> & { state?: Editor['state'] }
+
+export function optionalEditorState(editor: Editor): Editor['state'] | undefined {
+ return (editor as EditorWithOptionalState).state
+}
+
export function snappingThreshold(editor: Editor): number {
return SNAP_THRESHOLD_SCREEN_PX / Math.max(editor.state.zoom, Number.EPSILON)
}