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 { calculateResizeRect } from '#vue/shared/input/resize/rect'
|
||||||
import { applyResizeSnap } from '#vue/shared/input/resize/snap'
|
import { applyResizeSnap } from '#vue/shared/input/resize/snap'
|
||||||
|
import { optionalEditorState } from '#vue/shared/input/snap'
|
||||||
import type { DragResize } from '#vue/shared/input/types'
|
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) {
|
export function commitResizePreview(dragState: DragResize, editor: Editor) {
|
||||||
// See applyResize — reactive drag state must not leak into graph writes.
|
// See applyResize — reactive drag state must not leak into graph writes.
|
||||||
const d = toRaw(dragState)
|
const d = toRaw(dragState)
|
||||||
editor.state.snapGuides = []
|
optionalEditorState(editor)?.snapGuides.splice(0)
|
||||||
const node = editor.graph.getNode(d.nodeId)
|
const node = editor.graph.getNode(d.nodeId)
|
||||||
if (!node) return
|
if (!node) return
|
||||||
const finalChanges = snapshotResizeFinal(node)
|
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 { explicitSnapTargets } from '#vue/shared/input/explicit-snap-targets'
|
||||||
import {
|
import {
|
||||||
|
optionalEditorState,
|
||||||
resolveObjectPixelSnap,
|
resolveObjectPixelSnap,
|
||||||
worldBoundsNode,
|
worldBoundsNode,
|
||||||
worldDeltaToParentLocal
|
worldDeltaToParentLocal
|
||||||
|
|
@ -79,8 +80,9 @@ export function applyResizeSnap(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
disableSnapping: boolean
|
disableSnapping: boolean
|
||||||
): Rect {
|
): Rect {
|
||||||
if (disableSnapping || !editor.state) {
|
const state = optionalEditorState(editor)
|
||||||
if (editor.state) editor.state.snapGuides = []
|
if (disableSnapping || !state) {
|
||||||
|
if (state) state.snapGuides = []
|
||||||
return rect
|
return rect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,6 +110,6 @@ export function applyResizeSnap(
|
||||||
const dx = horizontal ? localCorrection.x : 0
|
const dx = horizontal ? localCorrection.x : 0
|
||||||
const dy = vertical ? localCorrection.y : 0
|
const dy = vertical ? localCorrection.y : 0
|
||||||
|
|
||||||
editor.state.snapGuides = snap.guides
|
state.snapGuides = snap.guides
|
||||||
return applyEdgeDelta(drag.handle, rect, dx, dy)
|
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 }
|
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 {
|
export function snappingThreshold(editor: Editor): number {
|
||||||
return SNAP_THRESHOLD_SCREEN_PX / Math.max(editor.state.zoom, Number.EPSILON)
|
return SNAP_THRESHOLD_SCREEN_PX / Math.max(editor.state.zoom, Number.EPSILON)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue