fix flipping for arrows (#3780)
@SomeHats and me fixed arrow flipping, which was a little bit broken after the bindings things ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [x] `bugfix` — Bug fix - [ ] `feature` — New feature - [ ] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Add a step-by-step description of how to test your PR here. 2. - [ ] Unit Tests - [ ] End to end tests ### Release Notes - Add a brief release note for your PR here. --------- Co-authored-by: Alex <alex@dytry.ch>
This commit is contained in:
parent
2cf8104f5a
commit
16ba1eb2c2
5 changed files with 45 additions and 31 deletions
|
@ -2543,6 +2543,7 @@ export type TLResizeShapeOptions = Partial<{
|
|||
mode: TLResizeMode;
|
||||
scaleAxisRotation: number;
|
||||
scaleOrigin: VecLike;
|
||||
skipStartAndEndCallbacks: boolean;
|
||||
}>;
|
||||
|
||||
// @public
|
||||
|
|
|
@ -168,6 +168,7 @@ export type TLResizeShapeOptions = Partial<{
|
|||
dragHandle: TLResizeHandle
|
||||
isAspectRatioLocked: boolean
|
||||
mode: TLResizeMode
|
||||
skipStartAndEndCallbacks: boolean
|
||||
}>
|
||||
|
||||
/** @public */
|
||||
|
@ -6323,8 +6324,15 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
// need to adjust the shape's x and y points in case the parent has moved since start of resizing
|
||||
const { x, y } = this.getPointInParentSpace(initialShape.id, initialPagePoint)
|
||||
|
||||
this.updateShapes([
|
||||
{
|
||||
let workingShape = initialShape
|
||||
if (!options.skipStartAndEndCallbacks) {
|
||||
workingShape = applyPartialToRecordWithProps(
|
||||
initialShape,
|
||||
util.onResizeStart?.(initialShape) ?? undefined
|
||||
)
|
||||
}
|
||||
|
||||
workingShape = applyPartialToRecordWithProps(workingShape, {
|
||||
id,
|
||||
type: initialShape.type as any,
|
||||
x: newLocalPoint.x,
|
||||
|
@ -6342,8 +6350,16 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
initialShape,
|
||||
}
|
||||
),
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
if (!options.skipStartAndEndCallbacks) {
|
||||
workingShape = applyPartialToRecordWithProps(
|
||||
workingShape,
|
||||
util.onResizeEnd?.(initialShape, workingShape) ?? undefined
|
||||
)
|
||||
}
|
||||
|
||||
this.updateShapes([workingShape])
|
||||
} else {
|
||||
const initialPageCenter = Mat.applyToPoint(pageTransform, initialBounds.center)
|
||||
// get the model changes from the shape util
|
||||
|
|
|
@ -97,7 +97,6 @@ import { TLOnDoubleClickHandler } from '@tldraw/editor';
|
|||
import { TLOnEditEndHandler } from '@tldraw/editor';
|
||||
import { TLOnHandleDragHandler } from '@tldraw/editor';
|
||||
import { TLOnResizeHandler } from '@tldraw/editor';
|
||||
import { TLOnResizeStartHandler } from '@tldraw/editor';
|
||||
import { TLOnTranslateHandler } from '@tldraw/editor';
|
||||
import { TLOnTranslateStartHandler } from '@tldraw/editor';
|
||||
import { TLPageId } from '@tldraw/editor';
|
||||
|
@ -206,8 +205,6 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|||
// (undocumented)
|
||||
onResize: TLOnResizeHandler<TLArrowShape>;
|
||||
// (undocumented)
|
||||
onResizeStart?: TLOnResizeStartHandler<TLArrowShape>;
|
||||
// (undocumented)
|
||||
onTranslate?: TLOnTranslateHandler<TLArrowShape>;
|
||||
// (undocumented)
|
||||
onTranslateStart: TLOnTranslateStartHandler<TLArrowShape>;
|
||||
|
|
|
@ -15,13 +15,13 @@ import {
|
|||
TLOnEditEndHandler,
|
||||
TLOnHandleDragHandler,
|
||||
TLOnResizeHandler,
|
||||
TLOnResizeStartHandler,
|
||||
TLOnTranslateHandler,
|
||||
TLOnTranslateStartHandler,
|
||||
TLShapePartial,
|
||||
TLShapeUtilCanvasSvgDef,
|
||||
TLShapeUtilFlag,
|
||||
Vec,
|
||||
WeakCache,
|
||||
arrowShapeMigrations,
|
||||
arrowShapeProps,
|
||||
getDefaultColorTheme,
|
||||
|
@ -406,15 +406,14 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|||
}
|
||||
}
|
||||
|
||||
// replace this with memo bag?
|
||||
private _resizeInitialBindings: TLArrowBindings = { start: undefined, end: undefined }
|
||||
override onResizeStart?: TLOnResizeStartHandler<TLArrowShape> = (shape) => {
|
||||
this._resizeInitialBindings = getArrowBindings(this.editor, shape)
|
||||
}
|
||||
private readonly _resizeInitialBindings = new WeakCache<TLArrowShape, TLArrowBindings>()
|
||||
|
||||
override onResize: TLOnResizeHandler<TLArrowShape> = (shape, info) => {
|
||||
const { scaleX, scaleY } = info
|
||||
|
||||
const bindings = this._resizeInitialBindings
|
||||
const bindings = this._resizeInitialBindings.get(shape, () =>
|
||||
getArrowBindings(this.editor, shape)
|
||||
)
|
||||
const terminals = getArrowTerminalsInArrowSpace(this.editor, shape, bindings)
|
||||
|
||||
const { start, end } = structuredClone<TLArrowShape['props']>(shape.props)
|
||||
|
|
|
@ -329,6 +329,7 @@ export class Resizing extends StateNode {
|
|||
scaleOrigin: scaleOriginPage,
|
||||
isAspectRatioLocked,
|
||||
scaleAxisRotation: selectionRotation,
|
||||
skipStartAndEndCallbacks: true,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue