fix(vue): guard optional resize test state without lint noise
This commit is contained in:
parent
f4ef46a249
commit
17f791ffe4
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue