kopia lustrzana https://github.com/Tldraw/Tldraw
alex/bindings: rename arrow binding helpres
rodzic
2150fc5281
commit
c01116039a
|
@ -144,12 +144,6 @@ export class Arc2d extends Geometry2d {
|
|||
// @public
|
||||
export function areAnglesCompatible(a: number, b: number): boolean;
|
||||
|
||||
// @internal
|
||||
export function arrowBindingMakeItNotSo(editor: Editor, arrow: TLArrowShape, terminal: 'end' | 'start'): void;
|
||||
|
||||
// @internal
|
||||
export function arrowBindingMakeItSo(editor: Editor, arrow: TLArrowShape | TLShapeId, target: TLShape | TLShapeId, props: TLArrowBindingProps): void;
|
||||
|
||||
export { Atom }
|
||||
|
||||
export { atom }
|
||||
|
@ -456,6 +450,9 @@ export const coreShapes: readonly [typeof GroupShapeUtil];
|
|||
// @public
|
||||
export function counterClockwiseAngleDist(a0: number, a1: number): number;
|
||||
|
||||
// @internal
|
||||
export function createOrUpdateArrowBinding(editor: Editor, arrow: TLArrowShape | TLShapeId, target: TLShape | TLShapeId, props: TLArrowBindingProps): void;
|
||||
|
||||
// @public
|
||||
export function createSessionStateSnapshotSignal(store: TLStore): Signal<null | TLSessionStateSnapshot>;
|
||||
|
||||
|
@ -1715,6 +1712,9 @@ export function refreshPage(): void;
|
|||
// @public (undocumented)
|
||||
export function releasePointerCapture(element: Element, event: PointerEvent | React_2.PointerEvent<Element>): void;
|
||||
|
||||
// @internal
|
||||
export function removeArrowBinding(editor: Editor, arrow: TLArrowShape, terminal: 'end' | 'start'): void;
|
||||
|
||||
// @public (undocumented)
|
||||
export type RequiredKeys<T, K extends keyof T> = Partial<Omit<T, K>> & Pick<T, K>;
|
||||
|
||||
|
|
|
@ -189,10 +189,10 @@ export {
|
|||
type TLArrowPoint,
|
||||
} from './lib/editor/shapes/shared/arrow/arrow-types'
|
||||
export {
|
||||
arrowBindingMakeItNotSo,
|
||||
arrowBindingMakeItSo,
|
||||
createOrUpdateArrowBinding,
|
||||
getArrowBindings,
|
||||
getArrowTerminalsInArrowSpace,
|
||||
removeArrowBinding,
|
||||
type TLArrowBindings,
|
||||
} from './lib/editor/shapes/shared/arrow/shared'
|
||||
export { resizeBox, type ResizeBoxOptions } from './lib/editor/shapes/shared/resizeBox'
|
||||
|
|
|
@ -140,10 +140,9 @@ export function getArrowTerminalsInArrowSpace(
|
|||
|
||||
/**
|
||||
* Create or update the arrow binding for a particular arrow terminal. Will clear up if needed.
|
||||
* TODO(alex): #bindings find a better name for this
|
||||
* @internal
|
||||
*/
|
||||
export function arrowBindingMakeItSo(
|
||||
export function createOrUpdateArrowBinding(
|
||||
editor: Editor,
|
||||
arrow: TLArrowShape | TLShapeId,
|
||||
target: TLShape | TLShapeId,
|
||||
|
@ -182,11 +181,7 @@ export function arrowBindingMakeItSo(
|
|||
* Remove any arrow bindings for a particular terminal.
|
||||
* @internal
|
||||
*/
|
||||
export function arrowBindingMakeItNotSo(
|
||||
editor: Editor,
|
||||
arrow: TLArrowShape,
|
||||
terminal: 'start' | 'end'
|
||||
) {
|
||||
export function removeArrowBinding(editor: Editor, arrow: TLArrowShape, terminal: 'start' | 'end') {
|
||||
const existing = editor
|
||||
.getBindingsFromShape<TLArrowBinding>(arrow, 'arrow')
|
||||
.filter((b) => b.props.terminal === terminal)
|
||||
|
|
|
@ -14,7 +14,6 @@ import {
|
|||
TLShapeId,
|
||||
TLShapePartial,
|
||||
Vec,
|
||||
arrowBindingMakeItNotSo,
|
||||
arrowBindingMigrations,
|
||||
arrowBindingProps,
|
||||
assert,
|
||||
|
@ -22,6 +21,7 @@ import {
|
|||
getIndexAbove,
|
||||
getIndexBetween,
|
||||
intersectLineSegmentCircle,
|
||||
removeArrowBinding,
|
||||
} from '@tldraw/editor'
|
||||
|
||||
export class ArrowBindingUtil extends BindingUtil<TLArrowBinding> {
|
||||
|
@ -220,5 +220,5 @@ function unbindArrowTerminal(editor: Editor, arrow: TLArrowShape, terminal: 'sta
|
|||
}
|
||||
|
||||
editor.updateShape(update)
|
||||
arrowBindingMakeItNotSo(editor, arrow, terminal)
|
||||
removeArrowBinding(editor, arrow, terminal)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import {
|
|||
HALF_PI,
|
||||
TLArrowShape,
|
||||
TLShapeId,
|
||||
arrowBindingMakeItSo,
|
||||
createOrUpdateArrowBinding,
|
||||
createShapeId,
|
||||
getArrowBindings,
|
||||
} from '@tldraw/editor'
|
||||
|
@ -55,14 +55,14 @@ beforeEach(() => {
|
|||
},
|
||||
])
|
||||
|
||||
arrowBindingMakeItSo(editor, ids.arrow1, ids.box1, {
|
||||
createOrUpdateArrowBinding(editor, ids.arrow1, ids.box1, {
|
||||
terminal: 'start',
|
||||
isExact: false,
|
||||
isPrecise: false,
|
||||
normalizedAnchor: { x: 0.5, y: 0.5 },
|
||||
})
|
||||
|
||||
arrowBindingMakeItSo(editor, ids.arrow1, ids.box2, {
|
||||
createOrUpdateArrowBinding(editor, ids.arrow1, ids.box2, {
|
||||
terminal: 'end',
|
||||
isExact: false,
|
||||
isPrecise: false,
|
||||
|
|
|
@ -23,14 +23,14 @@ import {
|
|||
TLShapeUtilCanvasSvgDef,
|
||||
TLShapeUtilFlag,
|
||||
Vec,
|
||||
arrowBindingMakeItNotSo,
|
||||
arrowBindingMakeItSo,
|
||||
arrowShapeMigrations,
|
||||
arrowShapeProps,
|
||||
createOrUpdateArrowBinding,
|
||||
getArrowBindings,
|
||||
getArrowTerminalsInArrowSpace,
|
||||
getDefaultColorTheme,
|
||||
mapObjectMapValues,
|
||||
removeArrowBinding,
|
||||
structuredClone,
|
||||
toDomPrecision,
|
||||
track,
|
||||
|
@ -204,7 +204,7 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|||
if (this.editor.inputs.ctrlKey) {
|
||||
// todo: maybe double check that this isn't equal to the other handle too?
|
||||
// Skip binding
|
||||
arrowBindingMakeItNotSo(this.editor, shape, handleId)
|
||||
removeArrowBinding(this.editor, shape, handleId)
|
||||
|
||||
update.props![handleId] = {
|
||||
x: handle.x,
|
||||
|
@ -226,7 +226,7 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|||
|
||||
if (!target) {
|
||||
// todo: maybe double check that this isn't equal to the other handle too?
|
||||
arrowBindingMakeItNotSo(this.editor, shape, handleId)
|
||||
removeArrowBinding(this.editor, shape, handleId)
|
||||
|
||||
update.props![handleId] = {
|
||||
x: handle.x,
|
||||
|
@ -290,7 +290,7 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|||
isExact: this.editor.inputs.altKey,
|
||||
}
|
||||
|
||||
arrowBindingMakeItSo(this.editor, shape, target.id, b)
|
||||
createOrUpdateArrowBinding(this.editor, shape, target.id, b)
|
||||
|
||||
this.editor.setHintingShapes([target.id])
|
||||
|
||||
|
@ -299,7 +299,7 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|||
if (
|
||||
Vec.Equals(newBindings.start.props.normalizedAnchor, newBindings.end.props.normalizedAnchor)
|
||||
) {
|
||||
arrowBindingMakeItSo(this.editor, shape, newBindings.end.toId, {
|
||||
createOrUpdateArrowBinding(this.editor, shape, newBindings.end.toId, {
|
||||
...newBindings.end.props,
|
||||
normalizedAnchor: {
|
||||
x: newBindings.end.props.normalizedAnchor.x + 0.05,
|
||||
|
@ -392,13 +392,13 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|||
x: (pointInTargetSpace.x - targetBounds.minX) / targetBounds.width,
|
||||
y: (pointInTargetSpace.y - targetBounds.minY) / targetBounds.height,
|
||||
}
|
||||
arrowBindingMakeItSo(this.editor, shape, newTarget.id, {
|
||||
createOrUpdateArrowBinding(this.editor, shape, newTarget.id, {
|
||||
...terminalBinding.binding.props,
|
||||
normalizedAnchor,
|
||||
isPrecise: true,
|
||||
})
|
||||
} else {
|
||||
arrowBindingMakeItNotSo(this.editor, shape, terminalBinding.binding.props.terminal)
|
||||
removeArrowBinding(this.editor, shape, terminalBinding.binding.props.terminal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -487,13 +487,13 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
|
|||
}
|
||||
|
||||
if (bindings.start && startNormalizedAnchor) {
|
||||
arrowBindingMakeItSo(this.editor, shape, bindings.start.toId, {
|
||||
createOrUpdateArrowBinding(this.editor, shape, bindings.start.toId, {
|
||||
...bindings.start.props,
|
||||
normalizedAnchor: startNormalizedAnchor.toJson(),
|
||||
})
|
||||
}
|
||||
if (bindings.end && endNormalizedAnchor) {
|
||||
arrowBindingMakeItSo(this.editor, shape, bindings.end.toId, {
|
||||
createOrUpdateArrowBinding(this.editor, shape, bindings.end.toId, {
|
||||
...bindings.end.props,
|
||||
normalizedAnchor: endNormalizedAnchor.toJson(),
|
||||
})
|
||||
|
|
Ładowanie…
Reference in New Issue