tldraw 4.5.5 → 4.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/bindings/arrow/ArrowBindingUtil.js +39 -10
- package/dist-cjs/lib/bindings/arrow/ArrowBindingUtil.js.map +2 -2
- package/dist-cjs/lib/ui/version.js +2 -2
- package/dist-cjs/lib/ui/version.js.map +1 -1
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/bindings/arrow/ArrowBindingUtil.mjs +39 -11
- package/dist-esm/lib/bindings/arrow/ArrowBindingUtil.mjs.map +2 -2
- package/dist-esm/lib/ui/version.mjs +2 -2
- package/dist-esm/lib/ui/version.mjs.map +1 -1
- package/package.json +3 -3
- package/src/lib/bindings/arrow/ArrowBindingUtil.ts +52 -12
- package/src/lib/ui/version.ts +2 -2
- package/src/test/commands/deleteShapes.test.ts +51 -0
package/dist-cjs/index.js
CHANGED
|
@@ -606,7 +606,7 @@ var import_buildFromV1Document = require("./lib/utils/tldr/buildFromV1Document")
|
|
|
606
606
|
var import_file = require("./lib/utils/tldr/file");
|
|
607
607
|
(0, import_editor.registerTldrawLibraryVersion)(
|
|
608
608
|
"tldraw",
|
|
609
|
-
"4.5.
|
|
609
|
+
"4.5.7",
|
|
610
610
|
"cjs"
|
|
611
611
|
);
|
|
612
612
|
//# sourceMappingURL=index.js.map
|
|
@@ -167,8 +167,14 @@ function updateArrowTerminal({
|
|
|
167
167
|
if (!info) {
|
|
168
168
|
throw new Error("expected arrow info");
|
|
169
169
|
}
|
|
170
|
-
const startPoint =
|
|
171
|
-
|
|
170
|
+
const startPoint = getValidTerminalPoint(
|
|
171
|
+
useHandle ? info.start.handle : info.start.point,
|
|
172
|
+
arrow.props.start
|
|
173
|
+
);
|
|
174
|
+
const endPoint = getValidTerminalPoint(
|
|
175
|
+
useHandle ? info.end.handle : info.end.point,
|
|
176
|
+
arrow.props.end
|
|
177
|
+
);
|
|
172
178
|
const point = terminal === "start" ? startPoint : endPoint;
|
|
173
179
|
const update = {
|
|
174
180
|
id: arrow.id,
|
|
@@ -179,20 +185,40 @@ function updateArrowTerminal({
|
|
|
179
185
|
}
|
|
180
186
|
};
|
|
181
187
|
if (info.type === "arc") {
|
|
182
|
-
const newStart = terminal === "start" ? startPoint : info.start.handle;
|
|
183
|
-
const newEnd = terminal === "end" ? endPoint : info.end.handle;
|
|
188
|
+
const newStart = terminal === "start" ? startPoint : getValidTerminalPoint(info.start.handle, arrow.props.start);
|
|
189
|
+
const newEnd = terminal === "end" ? endPoint : getValidTerminalPoint(info.end.handle, arrow.props.end);
|
|
184
190
|
const newMidPoint = import_editor.Vec.Med(newStart, newEnd);
|
|
185
|
-
const
|
|
191
|
+
const arrowDirection = import_editor.Vec.Sub(newStart, newEnd);
|
|
192
|
+
if ((0, import_editor.approximately)(import_editor.Vec.Len2(arrowDirection), 0)) {
|
|
193
|
+
editor.updateShape(update);
|
|
194
|
+
if (unbind) {
|
|
195
|
+
(0, import_shared.removeArrowBinding)(editor, arrow, terminal);
|
|
196
|
+
}
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const lineSegment = arrowDirection.per().uni().mul(info.handleArc.radius * 2 * Math.sign(arrow.props.bend));
|
|
200
|
+
const targetPoint = import_editor.Vec.Add(newMidPoint, lineSegment);
|
|
201
|
+
if (!import_editor.Vec.IsFinite(info.handleArc.center) || !Number.isFinite(info.handleArc.radius) || !import_editor.Vec.IsFinite(targetPoint)) {
|
|
202
|
+
editor.updateShape(update);
|
|
203
|
+
if (unbind) {
|
|
204
|
+
(0, import_shared.removeArrowBinding)(editor, arrow, terminal);
|
|
205
|
+
}
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
186
208
|
const intersections = (0, import_editor.intersectLineSegmentCircle)(
|
|
187
209
|
info.handleArc.center,
|
|
188
|
-
|
|
210
|
+
targetPoint,
|
|
189
211
|
info.handleArc.center,
|
|
190
212
|
info.handleArc.radius
|
|
191
213
|
);
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
214
|
+
if (intersections?.length) {
|
|
215
|
+
const intersection = intersections.reduce(
|
|
216
|
+
(closest, candidate) => import_editor.Vec.Dist2(candidate, targetPoint) < import_editor.Vec.Dist2(closest, targetPoint) ? candidate : closest
|
|
217
|
+
);
|
|
218
|
+
const bend = import_editor.Vec.Dist(newMidPoint, intersection) * Math.sign(arrow.props.bend);
|
|
219
|
+
if (!(0, import_editor.approximately)(bend, update.props.bend)) {
|
|
220
|
+
update.props.bend = bend;
|
|
221
|
+
}
|
|
196
222
|
}
|
|
197
223
|
}
|
|
198
224
|
editor.updateShape(update);
|
|
@@ -200,4 +226,7 @@ function updateArrowTerminal({
|
|
|
200
226
|
(0, import_shared.removeArrowBinding)(editor, arrow, terminal);
|
|
201
227
|
}
|
|
202
228
|
}
|
|
229
|
+
function getValidTerminalPoint(point, fallback) {
|
|
230
|
+
return import_editor.Vec.From(import_editor.Vec.IsFinite(point) ? point : fallback);
|
|
231
|
+
}
|
|
203
232
|
//# sourceMappingURL=ArrowBindingUtil.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/bindings/arrow/ArrowBindingUtil.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tBindingOnChangeOptions,\n\tBindingOnCreateOptions,\n\tBindingOnShapeChangeOptions,\n\tBindingOnShapeIsolateOptions,\n\tBindingUtil,\n\tEditor,\n\tIndexKey,\n\tTLArrowBinding,\n\tTLArrowBindingProps,\n\tTLArrowShape,\n\tTLParentId,\n\tTLShape,\n\tTLShapeId,\n\tTLShapePartial,\n\tVec,\n\tapproximately,\n\tarrowBindingMigrations,\n\tarrowBindingProps,\n\tassert,\n\tgetIndexAbove,\n\tgetIndexBetween,\n\tintersectLineSegmentCircle,\n} from '@tldraw/editor'\nimport { getArrowInfo } from '../../shapes/arrow/getArrowInfo'\nimport { getArrowBindings, removeArrowBinding } from '../../shapes/arrow/shared'\n\n/**\n * @public\n */\nexport class ArrowBindingUtil extends BindingUtil<TLArrowBinding> {\n\tstatic override type = 'arrow'\n\n\tstatic override props = arrowBindingProps\n\tstatic override migrations = arrowBindingMigrations\n\n\toverride getDefaultProps(): Partial<TLArrowBindingProps> {\n\t\treturn {\n\t\t\tisPrecise: false,\n\t\t\tisExact: false,\n\t\t\tnormalizedAnchor: { x: 0.5, y: 0.5 },\n\t\t\tsnap: 'none',\n\t\t}\n\t}\n\n\t// when the binding itself changes\n\toverride onAfterCreate({ binding }: BindingOnCreateOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape(binding.fromId) as TLArrowShape | undefined\n\t\tif (!arrow) return\n\t\tarrowDidUpdate(this.editor, arrow)\n\t}\n\n\t// when the binding itself changes\n\toverride onAfterChange({ bindingAfter }: BindingOnChangeOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape(bindingAfter.fromId) as TLArrowShape | undefined\n\t\tif (!arrow) return\n\t\tarrowDidUpdate(this.editor, arrow)\n\t}\n\n\t// when the arrow itself changes\n\toverride onAfterChangeFromShape({\n\t\tshapeBefore,\n\t\tshapeAfter,\n\t\treason,\n\t}: BindingOnShapeChangeOptions<TLArrowBinding>): void {\n\t\t// When translating arrows together with their bound shapes, only x/y changes.\n\t\t// In this case, bindings remain valid and no reparenting is needed.\n\t\t// This is a significant performance optimization when moving many bound shapes.\n\t\tif (\n\t\t\treason !== 'ancestry' &&\n\t\t\tshapeBefore.parentId === shapeAfter.parentId &&\n\t\t\tshapeBefore.index === shapeAfter.index\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\tarrowDidUpdate(this.editor, shapeAfter as TLArrowShape)\n\t}\n\n\t// when the shape an arrow is bound to changes\n\toverride onAfterChangeToShape({\n\t\tbinding,\n\t\tshapeBefore,\n\t\tshapeAfter,\n\t\treason,\n\t}: BindingOnShapeChangeOptions<TLArrowBinding>): void {\n\t\tif (\n\t\t\treason !== 'ancestry' &&\n\t\t\tshapeBefore.parentId === shapeAfter.parentId &&\n\t\t\tshapeBefore.index === shapeAfter.index\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\treparentArrow(this.editor, binding.fromId)\n\t}\n\n\t// when the arrow is isolated we need to update it's x,y positions\n\toverride onBeforeIsolateFromShape({\n\t\tbinding,\n\t}: BindingOnShapeIsolateOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape<TLArrowShape>(binding.fromId)\n\t\tif (!arrow) return\n\t\tupdateArrowTerminal({\n\t\t\teditor: this.editor,\n\t\t\tarrow,\n\t\t\tterminal: binding.props.terminal,\n\t\t})\n\t}\n}\n\nfunction reparentArrow(editor: Editor, arrowId: TLShapeId) {\n\tconst arrow = editor.getShape<TLArrowShape>(arrowId)\n\tif (!arrow) return\n\tconst bindings = getArrowBindings(editor, arrow)\n\tconst { start, end } = bindings\n\tconst startShape = start ? editor.getShape(start.toId) : undefined\n\tconst endShape = end ? editor.getShape(end.toId) : undefined\n\n\tconst parentPageId = editor.getAncestorPageId(arrow)\n\tif (!parentPageId) return\n\n\tlet nextParentId: TLParentId\n\tif (startShape && endShape) {\n\t\t// if arrow has two bindings, always parent arrow to closest common ancestor of the bindings\n\t\tnextParentId = editor.findCommonAncestor([startShape, endShape]) ?? parentPageId\n\t} else if (startShape || endShape) {\n\t\tconst bindingParentId = (startShape || endShape)?.parentId\n\t\t// If the arrow and the shape that it is bound to have the same parent, then keep that parent\n\t\tif (bindingParentId && bindingParentId === arrow.parentId) {\n\t\t\tnextParentId = arrow.parentId\n\t\t} else {\n\t\t\t// if arrow has one binding, keep arrow on its own page\n\t\t\tnextParentId = parentPageId\n\t\t}\n\t} else {\n\t\treturn\n\t}\n\n\tif (nextParentId && nextParentId !== arrow.parentId) {\n\t\teditor.reparentShapes([arrowId], nextParentId)\n\t}\n\n\tconst reparentedArrow = editor.getShape<TLArrowShape>(arrowId)\n\tif (!reparentedArrow) throw Error('no reparented arrow')\n\n\tconst startSibling = editor.getShapeNearestSibling(reparentedArrow, startShape)\n\tconst endSibling = editor.getShapeNearestSibling(reparentedArrow, endShape)\n\n\tlet highestSibling: TLShape | undefined\n\n\tif (startSibling && endSibling) {\n\t\thighestSibling = startSibling.index > endSibling.index ? startSibling : endSibling\n\t} else if (startSibling && !endSibling) {\n\t\thighestSibling = startSibling\n\t} else if (endSibling && !startSibling) {\n\t\thighestSibling = endSibling\n\t} else {\n\t\treturn\n\t}\n\n\tlet finalIndex: IndexKey\n\n\tconst higherSiblings = editor\n\t\t.getSortedChildIdsForParent(highestSibling.parentId)\n\t\t.map((id) => editor.getShape(id)!)\n\t\t.filter((sibling) => sibling.index > highestSibling!.index)\n\n\tif (higherSiblings.length) {\n\t\t// there are siblings above the highest bound sibling, we need to\n\t\t// insert between them.\n\n\t\t// if the next sibling is also a bound arrow though, we can end up\n\t\t// all fighting for the same indexes. so lets find the next\n\t\t// non-arrow sibling...\n\t\tconst nextHighestNonArrowSibling = higherSiblings.find((sibling) => sibling.type !== 'arrow')\n\n\t\tif (\n\t\t\t// ...then, if we're above the last shape we want to be above...\n\t\t\treparentedArrow.index > highestSibling.index &&\n\t\t\t// ...but below the next non-arrow sibling...\n\t\t\t(!nextHighestNonArrowSibling || reparentedArrow.index < nextHighestNonArrowSibling.index)\n\t\t) {\n\t\t\t// ...then we're already in the right place. no need to update!\n\t\t\treturn\n\t\t}\n\n\t\t// otherwise, we need to find the index between the highest sibling\n\t\t// we want to be above, and the next highest sibling we want to be\n\t\t// below:\n\t\tfinalIndex = getIndexBetween(highestSibling.index, higherSiblings[0].index)\n\t} else {\n\t\t// if there are no siblings above us, we can just get the next index:\n\t\tfinalIndex = getIndexAbove(highestSibling.index)\n\t}\n\n\tif (finalIndex !== reparentedArrow.index) {\n\t\teditor.updateShapes([{ id: arrowId, type: 'arrow', index: finalIndex }])\n\t}\n}\n\nfunction arrowDidUpdate(editor: Editor, arrow: TLArrowShape) {\n\tconst bindings = getArrowBindings(editor, arrow)\n\t// if the shape is an arrow and its bound shape is on another page\n\t// or was deleted, unbind it\n\tfor (const handle of ['start', 'end'] as const) {\n\t\tconst binding = bindings[handle]\n\t\tif (!binding) continue\n\t\tconst boundShape = editor.getShape(binding.toId)\n\t\tconst isShapeInSamePageAsArrow =\n\t\t\teditor.getAncestorPageId(arrow) === editor.getAncestorPageId(boundShape)\n\t\tif (!boundShape || !isShapeInSamePageAsArrow) {\n\t\t\tupdateArrowTerminal({ editor, arrow, terminal: handle, unbind: true })\n\t\t}\n\t}\n\n\t// always check the arrow parents\n\treparentArrow(editor, arrow.id)\n}\n\n/** @internal */\nexport function updateArrowTerminal({\n\teditor,\n\tarrow,\n\tterminal,\n\tunbind = false,\n\tuseHandle = false,\n}: {\n\teditor: Editor\n\tarrow: TLArrowShape\n\tterminal: 'start' | 'end'\n\tunbind?: boolean\n\tuseHandle?: boolean\n}) {\n\tconst info = getArrowInfo(editor, arrow)\n\tif (!info) {\n\t\tthrow new Error('expected arrow info')\n\t}\n\n\tconst startPoint = useHandle ? info.start.handle : info.start.point\n\tconst endPoint = useHandle ? info.end.handle : info.end.point\n\tconst point = terminal === 'start' ? startPoint : endPoint\n\n\tconst update = {\n\t\tid: arrow.id,\n\t\ttype: 'arrow',\n\t\tprops: {\n\t\t\t[terminal]: { x: point.x, y: point.y },\n\t\t\tbend: arrow.props.bend,\n\t\t},\n\t} satisfies TLShapePartial<TLArrowShape>\n\n\t// fix up the bend:\n\tif (info.type === 'arc') {\n\t\t// find the new start/end points of the resulting arrow\n\t\tconst newStart = terminal === 'start' ? startPoint : info.start.handle\n\t\tconst newEnd = terminal === 'end' ? endPoint : info.end.handle\n\t\tconst newMidPoint = Vec.Med(newStart, newEnd)\n\n\t\t// intersect a line segment perpendicular to the new arrow with the old arrow arc to\n\t\t// find the new mid-point\n\t\tconst lineSegment = Vec.Sub(newStart, newEnd)\n\t\t\t.per()\n\t\t\t.uni()\n\t\t\t.mul(info.handleArc.radius * 2 * Math.sign(arrow.props.bend))\n\n\t\t// find the intersections with the old arrow arc:\n\t\tconst intersections = intersectLineSegmentCircle(\n\t\t\tinfo.handleArc.center,\n\t\t\tVec.Add(newMidPoint, lineSegment),\n\t\t\tinfo.handleArc.center,\n\t\t\tinfo.handleArc.radius\n\t\t)\n\n\t\tassert(intersections?.length === 1)\n\t\tconst bend = Vec.Dist(newMidPoint, intersections[0]) * Math.sign(arrow.props.bend)\n\t\t// use `approximately` to avoid endless update loops\n\t\tif (!approximately(bend, update.props.bend)) {\n\t\t\tupdate.props.bend = bend\n\t\t}\n\t}\n\n\teditor.updateShape(update)\n\tif (unbind) {\n\t\tremoveArrowBinding(editor, arrow, terminal)\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n\tBindingOnChangeOptions,\n\tBindingOnCreateOptions,\n\tBindingOnShapeChangeOptions,\n\tBindingOnShapeIsolateOptions,\n\tBindingUtil,\n\tEditor,\n\tIndexKey,\n\tTLArrowBinding,\n\tTLArrowBindingProps,\n\tTLArrowShape,\n\tTLParentId,\n\tTLShape,\n\tTLShapeId,\n\tTLShapePartial,\n\tVec,\n\tapproximately,\n\tarrowBindingMigrations,\n\tarrowBindingProps,\n\tgetIndexAbove,\n\tgetIndexBetween,\n\tintersectLineSegmentCircle,\n} from '@tldraw/editor'\nimport { getArrowInfo } from '../../shapes/arrow/getArrowInfo'\nimport { getArrowBindings, removeArrowBinding } from '../../shapes/arrow/shared'\n\n/**\n * @public\n */\nexport class ArrowBindingUtil extends BindingUtil<TLArrowBinding> {\n\tstatic override type = 'arrow'\n\n\tstatic override props = arrowBindingProps\n\tstatic override migrations = arrowBindingMigrations\n\n\toverride getDefaultProps(): Partial<TLArrowBindingProps> {\n\t\treturn {\n\t\t\tisPrecise: false,\n\t\t\tisExact: false,\n\t\t\tnormalizedAnchor: { x: 0.5, y: 0.5 },\n\t\t\tsnap: 'none',\n\t\t}\n\t}\n\n\t// when the binding itself changes\n\toverride onAfterCreate({ binding }: BindingOnCreateOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape(binding.fromId) as TLArrowShape | undefined\n\t\tif (!arrow) return\n\t\tarrowDidUpdate(this.editor, arrow)\n\t}\n\n\t// when the binding itself changes\n\toverride onAfterChange({ bindingAfter }: BindingOnChangeOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape(bindingAfter.fromId) as TLArrowShape | undefined\n\t\tif (!arrow) return\n\t\tarrowDidUpdate(this.editor, arrow)\n\t}\n\n\t// when the arrow itself changes\n\toverride onAfterChangeFromShape({\n\t\tshapeBefore,\n\t\tshapeAfter,\n\t\treason,\n\t}: BindingOnShapeChangeOptions<TLArrowBinding>): void {\n\t\t// When translating arrows together with their bound shapes, only x/y changes.\n\t\t// In this case, bindings remain valid and no reparenting is needed.\n\t\t// This is a significant performance optimization when moving many bound shapes.\n\t\tif (\n\t\t\treason !== 'ancestry' &&\n\t\t\tshapeBefore.parentId === shapeAfter.parentId &&\n\t\t\tshapeBefore.index === shapeAfter.index\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\tarrowDidUpdate(this.editor, shapeAfter as TLArrowShape)\n\t}\n\n\t// when the shape an arrow is bound to changes\n\toverride onAfterChangeToShape({\n\t\tbinding,\n\t\tshapeBefore,\n\t\tshapeAfter,\n\t\treason,\n\t}: BindingOnShapeChangeOptions<TLArrowBinding>): void {\n\t\tif (\n\t\t\treason !== 'ancestry' &&\n\t\t\tshapeBefore.parentId === shapeAfter.parentId &&\n\t\t\tshapeBefore.index === shapeAfter.index\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\treparentArrow(this.editor, binding.fromId)\n\t}\n\n\t// when the arrow is isolated we need to update it's x,y positions\n\toverride onBeforeIsolateFromShape({\n\t\tbinding,\n\t}: BindingOnShapeIsolateOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape<TLArrowShape>(binding.fromId)\n\t\tif (!arrow) return\n\t\tupdateArrowTerminal({\n\t\t\teditor: this.editor,\n\t\t\tarrow,\n\t\t\tterminal: binding.props.terminal,\n\t\t})\n\t}\n}\n\nfunction reparentArrow(editor: Editor, arrowId: TLShapeId) {\n\tconst arrow = editor.getShape<TLArrowShape>(arrowId)\n\tif (!arrow) return\n\tconst bindings = getArrowBindings(editor, arrow)\n\tconst { start, end } = bindings\n\tconst startShape = start ? editor.getShape(start.toId) : undefined\n\tconst endShape = end ? editor.getShape(end.toId) : undefined\n\n\tconst parentPageId = editor.getAncestorPageId(arrow)\n\tif (!parentPageId) return\n\n\tlet nextParentId: TLParentId\n\tif (startShape && endShape) {\n\t\t// if arrow has two bindings, always parent arrow to closest common ancestor of the bindings\n\t\tnextParentId = editor.findCommonAncestor([startShape, endShape]) ?? parentPageId\n\t} else if (startShape || endShape) {\n\t\tconst bindingParentId = (startShape || endShape)?.parentId\n\t\t// If the arrow and the shape that it is bound to have the same parent, then keep that parent\n\t\tif (bindingParentId && bindingParentId === arrow.parentId) {\n\t\t\tnextParentId = arrow.parentId\n\t\t} else {\n\t\t\t// if arrow has one binding, keep arrow on its own page\n\t\t\tnextParentId = parentPageId\n\t\t}\n\t} else {\n\t\treturn\n\t}\n\n\tif (nextParentId && nextParentId !== arrow.parentId) {\n\t\teditor.reparentShapes([arrowId], nextParentId)\n\t}\n\n\tconst reparentedArrow = editor.getShape<TLArrowShape>(arrowId)\n\tif (!reparentedArrow) throw Error('no reparented arrow')\n\n\tconst startSibling = editor.getShapeNearestSibling(reparentedArrow, startShape)\n\tconst endSibling = editor.getShapeNearestSibling(reparentedArrow, endShape)\n\n\tlet highestSibling: TLShape | undefined\n\n\tif (startSibling && endSibling) {\n\t\thighestSibling = startSibling.index > endSibling.index ? startSibling : endSibling\n\t} else if (startSibling && !endSibling) {\n\t\thighestSibling = startSibling\n\t} else if (endSibling && !startSibling) {\n\t\thighestSibling = endSibling\n\t} else {\n\t\treturn\n\t}\n\n\tlet finalIndex: IndexKey\n\n\tconst higherSiblings = editor\n\t\t.getSortedChildIdsForParent(highestSibling.parentId)\n\t\t.map((id) => editor.getShape(id)!)\n\t\t.filter((sibling) => sibling.index > highestSibling!.index)\n\n\tif (higherSiblings.length) {\n\t\t// there are siblings above the highest bound sibling, we need to\n\t\t// insert between them.\n\n\t\t// if the next sibling is also a bound arrow though, we can end up\n\t\t// all fighting for the same indexes. so lets find the next\n\t\t// non-arrow sibling...\n\t\tconst nextHighestNonArrowSibling = higherSiblings.find((sibling) => sibling.type !== 'arrow')\n\n\t\tif (\n\t\t\t// ...then, if we're above the last shape we want to be above...\n\t\t\treparentedArrow.index > highestSibling.index &&\n\t\t\t// ...but below the next non-arrow sibling...\n\t\t\t(!nextHighestNonArrowSibling || reparentedArrow.index < nextHighestNonArrowSibling.index)\n\t\t) {\n\t\t\t// ...then we're already in the right place. no need to update!\n\t\t\treturn\n\t\t}\n\n\t\t// otherwise, we need to find the index between the highest sibling\n\t\t// we want to be above, and the next highest sibling we want to be\n\t\t// below:\n\t\tfinalIndex = getIndexBetween(highestSibling.index, higherSiblings[0].index)\n\t} else {\n\t\t// if there are no siblings above us, we can just get the next index:\n\t\tfinalIndex = getIndexAbove(highestSibling.index)\n\t}\n\n\tif (finalIndex !== reparentedArrow.index) {\n\t\teditor.updateShapes([{ id: arrowId, type: 'arrow', index: finalIndex }])\n\t}\n}\n\nfunction arrowDidUpdate(editor: Editor, arrow: TLArrowShape) {\n\tconst bindings = getArrowBindings(editor, arrow)\n\t// if the shape is an arrow and its bound shape is on another page\n\t// or was deleted, unbind it\n\tfor (const handle of ['start', 'end'] as const) {\n\t\tconst binding = bindings[handle]\n\t\tif (!binding) continue\n\t\tconst boundShape = editor.getShape(binding.toId)\n\t\tconst isShapeInSamePageAsArrow =\n\t\t\teditor.getAncestorPageId(arrow) === editor.getAncestorPageId(boundShape)\n\t\tif (!boundShape || !isShapeInSamePageAsArrow) {\n\t\t\tupdateArrowTerminal({ editor, arrow, terminal: handle, unbind: true })\n\t\t}\n\t}\n\n\t// always check the arrow parents\n\treparentArrow(editor, arrow.id)\n}\n\n/** @internal */\nexport function updateArrowTerminal({\n\teditor,\n\tarrow,\n\tterminal,\n\tunbind = false,\n\tuseHandle = false,\n}: {\n\teditor: Editor\n\tarrow: TLArrowShape\n\tterminal: 'start' | 'end'\n\tunbind?: boolean\n\tuseHandle?: boolean\n}) {\n\tconst info = getArrowInfo(editor, arrow)\n\tif (!info) {\n\t\tthrow new Error('expected arrow info')\n\t}\n\n\tconst startPoint = getValidTerminalPoint(\n\t\tuseHandle ? info.start.handle : info.start.point,\n\t\tarrow.props.start\n\t)\n\tconst endPoint = getValidTerminalPoint(\n\t\tuseHandle ? info.end.handle : info.end.point,\n\t\tarrow.props.end\n\t)\n\tconst point = terminal === 'start' ? startPoint : endPoint\n\n\tconst update = {\n\t\tid: arrow.id,\n\t\ttype: 'arrow',\n\t\tprops: {\n\t\t\t[terminal]: { x: point.x, y: point.y },\n\t\t\tbend: arrow.props.bend,\n\t\t},\n\t} satisfies TLShapePartial<TLArrowShape>\n\n\t// fix up the bend:\n\tif (info.type === 'arc') {\n\t\t// find the new start/end points of the resulting arrow\n\t\tconst newStart =\n\t\t\tterminal === 'start'\n\t\t\t\t? startPoint\n\t\t\t\t: getValidTerminalPoint(info.start.handle, arrow.props.start)\n\t\tconst newEnd =\n\t\t\tterminal === 'end' ? endPoint : getValidTerminalPoint(info.end.handle, arrow.props.end)\n\t\tconst newMidPoint = Vec.Med(newStart, newEnd)\n\t\tconst arrowDirection = Vec.Sub(newStart, newEnd)\n\t\tif (approximately(Vec.Len2(arrowDirection), 0)) {\n\t\t\teditor.updateShape(update)\n\t\t\tif (unbind) {\n\t\t\t\tremoveArrowBinding(editor, arrow, terminal)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\t// intersect a line segment perpendicular to the new arrow with the old arrow arc to\n\t\t// find the new mid-point\n\t\tconst lineSegment = arrowDirection\n\t\t\t.per()\n\t\t\t.uni()\n\t\t\t.mul(info.handleArc.radius * 2 * Math.sign(arrow.props.bend))\n\t\tconst targetPoint = Vec.Add(newMidPoint, lineSegment)\n\t\tif (\n\t\t\t!Vec.IsFinite(info.handleArc.center) ||\n\t\t\t!Number.isFinite(info.handleArc.radius) ||\n\t\t\t!Vec.IsFinite(targetPoint)\n\t\t) {\n\t\t\teditor.updateShape(update)\n\t\t\tif (unbind) {\n\t\t\t\tremoveArrowBinding(editor, arrow, terminal)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\t// find the intersections with the old arrow arc:\n\t\tconst intersections = intersectLineSegmentCircle(\n\t\t\tinfo.handleArc.center,\n\t\t\ttargetPoint,\n\t\t\tinfo.handleArc.center,\n\t\t\tinfo.handleArc.radius\n\t\t)\n\n\t\tif (intersections?.length) {\n\t\t\tconst intersection = intersections.reduce((closest, candidate) =>\n\t\t\t\tVec.Dist2(candidate, targetPoint) < Vec.Dist2(closest, targetPoint) ? candidate : closest\n\t\t\t)\n\t\t\tconst bend = Vec.Dist(newMidPoint, intersection) * Math.sign(arrow.props.bend)\n\t\t\t// use `approximately` to avoid endless update loops\n\t\t\tif (!approximately(bend, update.props.bend)) {\n\t\t\t\tupdate.props.bend = bend\n\t\t\t}\n\t\t}\n\t}\n\n\teditor.updateShape(update)\n\tif (unbind) {\n\t\tremoveArrowBinding(editor, arrow, terminal)\n\t}\n}\n\nfunction getValidTerminalPoint(\n\tpoint: { x: number; y: number },\n\tfallback: { x: number; y: number }\n) {\n\treturn Vec.From(Vec.IsFinite(point) ? point : fallback)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAsBO;AACP,0BAA6B;AAC7B,oBAAqD;AAK9C,MAAM,yBAAyB,0BAA4B;AAAA,EACjE,OAAgB,OAAO;AAAA,EAEvB,OAAgB,QAAQ;AAAA,EACxB,OAAgB,aAAa;AAAA,EAEpB,kBAAgD;AACxD,WAAO;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f,KAAK,UAAU;AAAA,IAChB;AAEA,QAAI,eAAe,QAAQ;AAC1B,YAAM,eAAe,cAAc;AAAA,QAAO,CAAC,SAAS,cACnD,kBAAI,MAAM,WAAW,WAAW,IAAI,kBAAI,MAAM,SAAS,WAAW,IAAI,YAAY;AAAA,MACnF;AACA,YAAM,OAAO,kBAAI,KAAK,aAAa,YAAY,IAAI,KAAK,KAAK,MAAM,MAAM,IAAI;AAE7E,UAAI,KAAC,6BAAc,MAAM,OAAO,MAAM,IAAI,GAAG;AAC5C,eAAO,MAAM,OAAO;AAAA,MACrB;AAAA,IACD;AAAA,EACD;AAEA,SAAO,YAAY,MAAM;AACzB,MAAI,QAAQ;AACX,0CAAmB,QAAQ,OAAO,QAAQ;AAAA,EAC3C;AACD;AAEA,SAAS,sBACR,OACA,UACC;AACD,SAAO,kBAAI,KAAK,kBAAI,SAAS,KAAK,IAAI,QAAQ,QAAQ;AACvD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -22,10 +22,10 @@ __export(version_exports, {
|
|
|
22
22
|
version: () => version
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(version_exports);
|
|
25
|
-
const version = "4.5.
|
|
25
|
+
const version = "4.5.7";
|
|
26
26
|
const publishDates = {
|
|
27
27
|
major: "2025-09-18T14:39:22.803Z",
|
|
28
28
|
minor: "2026-03-18T11:05:13.340Z",
|
|
29
|
-
patch: "2026-04-
|
|
29
|
+
patch: "2026-04-03T19:09:04.689Z"
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/ui/version.ts"],
|
|
4
|
-
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '4.5.
|
|
4
|
+
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '4.5.7'\nexport const publishDates = {\n\tmajor: '2025-09-18T14:39:22.803Z',\n\tminor: '2026-03-18T11:05:13.340Z',\n\tpatch: '2026-04-03T19:09:04.689Z',\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist-esm/index.mjs
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
approximately,
|
|
5
5
|
arrowBindingMigrations,
|
|
6
6
|
arrowBindingProps,
|
|
7
|
-
assert,
|
|
8
7
|
getIndexAbove,
|
|
9
8
|
getIndexBetween,
|
|
10
9
|
intersectLineSegmentCircle
|
|
@@ -153,8 +152,14 @@ function updateArrowTerminal({
|
|
|
153
152
|
if (!info) {
|
|
154
153
|
throw new Error("expected arrow info");
|
|
155
154
|
}
|
|
156
|
-
const startPoint =
|
|
157
|
-
|
|
155
|
+
const startPoint = getValidTerminalPoint(
|
|
156
|
+
useHandle ? info.start.handle : info.start.point,
|
|
157
|
+
arrow.props.start
|
|
158
|
+
);
|
|
159
|
+
const endPoint = getValidTerminalPoint(
|
|
160
|
+
useHandle ? info.end.handle : info.end.point,
|
|
161
|
+
arrow.props.end
|
|
162
|
+
);
|
|
158
163
|
const point = terminal === "start" ? startPoint : endPoint;
|
|
159
164
|
const update = {
|
|
160
165
|
id: arrow.id,
|
|
@@ -165,20 +170,40 @@ function updateArrowTerminal({
|
|
|
165
170
|
}
|
|
166
171
|
};
|
|
167
172
|
if (info.type === "arc") {
|
|
168
|
-
const newStart = terminal === "start" ? startPoint : info.start.handle;
|
|
169
|
-
const newEnd = terminal === "end" ? endPoint : info.end.handle;
|
|
173
|
+
const newStart = terminal === "start" ? startPoint : getValidTerminalPoint(info.start.handle, arrow.props.start);
|
|
174
|
+
const newEnd = terminal === "end" ? endPoint : getValidTerminalPoint(info.end.handle, arrow.props.end);
|
|
170
175
|
const newMidPoint = Vec.Med(newStart, newEnd);
|
|
171
|
-
const
|
|
176
|
+
const arrowDirection = Vec.Sub(newStart, newEnd);
|
|
177
|
+
if (approximately(Vec.Len2(arrowDirection), 0)) {
|
|
178
|
+
editor.updateShape(update);
|
|
179
|
+
if (unbind) {
|
|
180
|
+
removeArrowBinding(editor, arrow, terminal);
|
|
181
|
+
}
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const lineSegment = arrowDirection.per().uni().mul(info.handleArc.radius * 2 * Math.sign(arrow.props.bend));
|
|
185
|
+
const targetPoint = Vec.Add(newMidPoint, lineSegment);
|
|
186
|
+
if (!Vec.IsFinite(info.handleArc.center) || !Number.isFinite(info.handleArc.radius) || !Vec.IsFinite(targetPoint)) {
|
|
187
|
+
editor.updateShape(update);
|
|
188
|
+
if (unbind) {
|
|
189
|
+
removeArrowBinding(editor, arrow, terminal);
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
172
193
|
const intersections = intersectLineSegmentCircle(
|
|
173
194
|
info.handleArc.center,
|
|
174
|
-
|
|
195
|
+
targetPoint,
|
|
175
196
|
info.handleArc.center,
|
|
176
197
|
info.handleArc.radius
|
|
177
198
|
);
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
199
|
+
if (intersections?.length) {
|
|
200
|
+
const intersection = intersections.reduce(
|
|
201
|
+
(closest, candidate) => Vec.Dist2(candidate, targetPoint) < Vec.Dist2(closest, targetPoint) ? candidate : closest
|
|
202
|
+
);
|
|
203
|
+
const bend = Vec.Dist(newMidPoint, intersection) * Math.sign(arrow.props.bend);
|
|
204
|
+
if (!approximately(bend, update.props.bend)) {
|
|
205
|
+
update.props.bend = bend;
|
|
206
|
+
}
|
|
182
207
|
}
|
|
183
208
|
}
|
|
184
209
|
editor.updateShape(update);
|
|
@@ -186,6 +211,9 @@ function updateArrowTerminal({
|
|
|
186
211
|
removeArrowBinding(editor, arrow, terminal);
|
|
187
212
|
}
|
|
188
213
|
}
|
|
214
|
+
function getValidTerminalPoint(point, fallback) {
|
|
215
|
+
return Vec.From(Vec.IsFinite(point) ? point : fallback);
|
|
216
|
+
}
|
|
189
217
|
export {
|
|
190
218
|
ArrowBindingUtil,
|
|
191
219
|
updateArrowTerminal
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/bindings/arrow/ArrowBindingUtil.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tBindingOnChangeOptions,\n\tBindingOnCreateOptions,\n\tBindingOnShapeChangeOptions,\n\tBindingOnShapeIsolateOptions,\n\tBindingUtil,\n\tEditor,\n\tIndexKey,\n\tTLArrowBinding,\n\tTLArrowBindingProps,\n\tTLArrowShape,\n\tTLParentId,\n\tTLShape,\n\tTLShapeId,\n\tTLShapePartial,\n\tVec,\n\tapproximately,\n\tarrowBindingMigrations,\n\tarrowBindingProps,\n\tassert,\n\tgetIndexAbove,\n\tgetIndexBetween,\n\tintersectLineSegmentCircle,\n} from '@tldraw/editor'\nimport { getArrowInfo } from '../../shapes/arrow/getArrowInfo'\nimport { getArrowBindings, removeArrowBinding } from '../../shapes/arrow/shared'\n\n/**\n * @public\n */\nexport class ArrowBindingUtil extends BindingUtil<TLArrowBinding> {\n\tstatic override type = 'arrow'\n\n\tstatic override props = arrowBindingProps\n\tstatic override migrations = arrowBindingMigrations\n\n\toverride getDefaultProps(): Partial<TLArrowBindingProps> {\n\t\treturn {\n\t\t\tisPrecise: false,\n\t\t\tisExact: false,\n\t\t\tnormalizedAnchor: { x: 0.5, y: 0.5 },\n\t\t\tsnap: 'none',\n\t\t}\n\t}\n\n\t// when the binding itself changes\n\toverride onAfterCreate({ binding }: BindingOnCreateOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape(binding.fromId) as TLArrowShape | undefined\n\t\tif (!arrow) return\n\t\tarrowDidUpdate(this.editor, arrow)\n\t}\n\n\t// when the binding itself changes\n\toverride onAfterChange({ bindingAfter }: BindingOnChangeOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape(bindingAfter.fromId) as TLArrowShape | undefined\n\t\tif (!arrow) return\n\t\tarrowDidUpdate(this.editor, arrow)\n\t}\n\n\t// when the arrow itself changes\n\toverride onAfterChangeFromShape({\n\t\tshapeBefore,\n\t\tshapeAfter,\n\t\treason,\n\t}: BindingOnShapeChangeOptions<TLArrowBinding>): void {\n\t\t// When translating arrows together with their bound shapes, only x/y changes.\n\t\t// In this case, bindings remain valid and no reparenting is needed.\n\t\t// This is a significant performance optimization when moving many bound shapes.\n\t\tif (\n\t\t\treason !== 'ancestry' &&\n\t\t\tshapeBefore.parentId === shapeAfter.parentId &&\n\t\t\tshapeBefore.index === shapeAfter.index\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\tarrowDidUpdate(this.editor, shapeAfter as TLArrowShape)\n\t}\n\n\t// when the shape an arrow is bound to changes\n\toverride onAfterChangeToShape({\n\t\tbinding,\n\t\tshapeBefore,\n\t\tshapeAfter,\n\t\treason,\n\t}: BindingOnShapeChangeOptions<TLArrowBinding>): void {\n\t\tif (\n\t\t\treason !== 'ancestry' &&\n\t\t\tshapeBefore.parentId === shapeAfter.parentId &&\n\t\t\tshapeBefore.index === shapeAfter.index\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\treparentArrow(this.editor, binding.fromId)\n\t}\n\n\t// when the arrow is isolated we need to update it's x,y positions\n\toverride onBeforeIsolateFromShape({\n\t\tbinding,\n\t}: BindingOnShapeIsolateOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape<TLArrowShape>(binding.fromId)\n\t\tif (!arrow) return\n\t\tupdateArrowTerminal({\n\t\t\teditor: this.editor,\n\t\t\tarrow,\n\t\t\tterminal: binding.props.terminal,\n\t\t})\n\t}\n}\n\nfunction reparentArrow(editor: Editor, arrowId: TLShapeId) {\n\tconst arrow = editor.getShape<TLArrowShape>(arrowId)\n\tif (!arrow) return\n\tconst bindings = getArrowBindings(editor, arrow)\n\tconst { start, end } = bindings\n\tconst startShape = start ? editor.getShape(start.toId) : undefined\n\tconst endShape = end ? editor.getShape(end.toId) : undefined\n\n\tconst parentPageId = editor.getAncestorPageId(arrow)\n\tif (!parentPageId) return\n\n\tlet nextParentId: TLParentId\n\tif (startShape && endShape) {\n\t\t// if arrow has two bindings, always parent arrow to closest common ancestor of the bindings\n\t\tnextParentId = editor.findCommonAncestor([startShape, endShape]) ?? parentPageId\n\t} else if (startShape || endShape) {\n\t\tconst bindingParentId = (startShape || endShape)?.parentId\n\t\t// If the arrow and the shape that it is bound to have the same parent, then keep that parent\n\t\tif (bindingParentId && bindingParentId === arrow.parentId) {\n\t\t\tnextParentId = arrow.parentId\n\t\t} else {\n\t\t\t// if arrow has one binding, keep arrow on its own page\n\t\t\tnextParentId = parentPageId\n\t\t}\n\t} else {\n\t\treturn\n\t}\n\n\tif (nextParentId && nextParentId !== arrow.parentId) {\n\t\teditor.reparentShapes([arrowId], nextParentId)\n\t}\n\n\tconst reparentedArrow = editor.getShape<TLArrowShape>(arrowId)\n\tif (!reparentedArrow) throw Error('no reparented arrow')\n\n\tconst startSibling = editor.getShapeNearestSibling(reparentedArrow, startShape)\n\tconst endSibling = editor.getShapeNearestSibling(reparentedArrow, endShape)\n\n\tlet highestSibling: TLShape | undefined\n\n\tif (startSibling && endSibling) {\n\t\thighestSibling = startSibling.index > endSibling.index ? startSibling : endSibling\n\t} else if (startSibling && !endSibling) {\n\t\thighestSibling = startSibling\n\t} else if (endSibling && !startSibling) {\n\t\thighestSibling = endSibling\n\t} else {\n\t\treturn\n\t}\n\n\tlet finalIndex: IndexKey\n\n\tconst higherSiblings = editor\n\t\t.getSortedChildIdsForParent(highestSibling.parentId)\n\t\t.map((id) => editor.getShape(id)!)\n\t\t.filter((sibling) => sibling.index > highestSibling!.index)\n\n\tif (higherSiblings.length) {\n\t\t// there are siblings above the highest bound sibling, we need to\n\t\t// insert between them.\n\n\t\t// if the next sibling is also a bound arrow though, we can end up\n\t\t// all fighting for the same indexes. so lets find the next\n\t\t// non-arrow sibling...\n\t\tconst nextHighestNonArrowSibling = higherSiblings.find((sibling) => sibling.type !== 'arrow')\n\n\t\tif (\n\t\t\t// ...then, if we're above the last shape we want to be above...\n\t\t\treparentedArrow.index > highestSibling.index &&\n\t\t\t// ...but below the next non-arrow sibling...\n\t\t\t(!nextHighestNonArrowSibling || reparentedArrow.index < nextHighestNonArrowSibling.index)\n\t\t) {\n\t\t\t// ...then we're already in the right place. no need to update!\n\t\t\treturn\n\t\t}\n\n\t\t// otherwise, we need to find the index between the highest sibling\n\t\t// we want to be above, and the next highest sibling we want to be\n\t\t// below:\n\t\tfinalIndex = getIndexBetween(highestSibling.index, higherSiblings[0].index)\n\t} else {\n\t\t// if there are no siblings above us, we can just get the next index:\n\t\tfinalIndex = getIndexAbove(highestSibling.index)\n\t}\n\n\tif (finalIndex !== reparentedArrow.index) {\n\t\teditor.updateShapes([{ id: arrowId, type: 'arrow', index: finalIndex }])\n\t}\n}\n\nfunction arrowDidUpdate(editor: Editor, arrow: TLArrowShape) {\n\tconst bindings = getArrowBindings(editor, arrow)\n\t// if the shape is an arrow and its bound shape is on another page\n\t// or was deleted, unbind it\n\tfor (const handle of ['start', 'end'] as const) {\n\t\tconst binding = bindings[handle]\n\t\tif (!binding) continue\n\t\tconst boundShape = editor.getShape(binding.toId)\n\t\tconst isShapeInSamePageAsArrow =\n\t\t\teditor.getAncestorPageId(arrow) === editor.getAncestorPageId(boundShape)\n\t\tif (!boundShape || !isShapeInSamePageAsArrow) {\n\t\t\tupdateArrowTerminal({ editor, arrow, terminal: handle, unbind: true })\n\t\t}\n\t}\n\n\t// always check the arrow parents\n\treparentArrow(editor, arrow.id)\n}\n\n/** @internal */\nexport function updateArrowTerminal({\n\teditor,\n\tarrow,\n\tterminal,\n\tunbind = false,\n\tuseHandle = false,\n}: {\n\teditor: Editor\n\tarrow: TLArrowShape\n\tterminal: 'start' | 'end'\n\tunbind?: boolean\n\tuseHandle?: boolean\n}) {\n\tconst info = getArrowInfo(editor, arrow)\n\tif (!info) {\n\t\tthrow new Error('expected arrow info')\n\t}\n\n\tconst startPoint = useHandle ? info.start.handle : info.start.point\n\tconst endPoint = useHandle ? info.end.handle : info.end.point\n\tconst point = terminal === 'start' ? startPoint : endPoint\n\n\tconst update = {\n\t\tid: arrow.id,\n\t\ttype: 'arrow',\n\t\tprops: {\n\t\t\t[terminal]: { x: point.x, y: point.y },\n\t\t\tbend: arrow.props.bend,\n\t\t},\n\t} satisfies TLShapePartial<TLArrowShape>\n\n\t// fix up the bend:\n\tif (info.type === 'arc') {\n\t\t// find the new start/end points of the resulting arrow\n\t\tconst newStart = terminal === 'start' ? startPoint : info.start.handle\n\t\tconst newEnd = terminal === 'end' ? endPoint : info.end.handle\n\t\tconst newMidPoint = Vec.Med(newStart, newEnd)\n\n\t\t// intersect a line segment perpendicular to the new arrow with the old arrow arc to\n\t\t// find the new mid-point\n\t\tconst lineSegment = Vec.Sub(newStart, newEnd)\n\t\t\t.per()\n\t\t\t.uni()\n\t\t\t.mul(info.handleArc.radius * 2 * Math.sign(arrow.props.bend))\n\n\t\t// find the intersections with the old arrow arc:\n\t\tconst intersections = intersectLineSegmentCircle(\n\t\t\tinfo.handleArc.center,\n\t\t\tVec.Add(newMidPoint, lineSegment),\n\t\t\tinfo.handleArc.center,\n\t\t\tinfo.handleArc.radius\n\t\t)\n\n\t\tassert(intersections?.length === 1)\n\t\tconst bend = Vec.Dist(newMidPoint, intersections[0]) * Math.sign(arrow.props.bend)\n\t\t// use `approximately` to avoid endless update loops\n\t\tif (!approximately(bend, update.props.bend)) {\n\t\t\tupdate.props.bend = bend\n\t\t}\n\t}\n\n\teditor.updateShape(update)\n\tif (unbind) {\n\t\tremoveArrowBinding(editor, arrow, terminal)\n\t}\n}\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EAKC;AAAA,EAUA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n\tBindingOnChangeOptions,\n\tBindingOnCreateOptions,\n\tBindingOnShapeChangeOptions,\n\tBindingOnShapeIsolateOptions,\n\tBindingUtil,\n\tEditor,\n\tIndexKey,\n\tTLArrowBinding,\n\tTLArrowBindingProps,\n\tTLArrowShape,\n\tTLParentId,\n\tTLShape,\n\tTLShapeId,\n\tTLShapePartial,\n\tVec,\n\tapproximately,\n\tarrowBindingMigrations,\n\tarrowBindingProps,\n\tgetIndexAbove,\n\tgetIndexBetween,\n\tintersectLineSegmentCircle,\n} from '@tldraw/editor'\nimport { getArrowInfo } from '../../shapes/arrow/getArrowInfo'\nimport { getArrowBindings, removeArrowBinding } from '../../shapes/arrow/shared'\n\n/**\n * @public\n */\nexport class ArrowBindingUtil extends BindingUtil<TLArrowBinding> {\n\tstatic override type = 'arrow'\n\n\tstatic override props = arrowBindingProps\n\tstatic override migrations = arrowBindingMigrations\n\n\toverride getDefaultProps(): Partial<TLArrowBindingProps> {\n\t\treturn {\n\t\t\tisPrecise: false,\n\t\t\tisExact: false,\n\t\t\tnormalizedAnchor: { x: 0.5, y: 0.5 },\n\t\t\tsnap: 'none',\n\t\t}\n\t}\n\n\t// when the binding itself changes\n\toverride onAfterCreate({ binding }: BindingOnCreateOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape(binding.fromId) as TLArrowShape | undefined\n\t\tif (!arrow) return\n\t\tarrowDidUpdate(this.editor, arrow)\n\t}\n\n\t// when the binding itself changes\n\toverride onAfterChange({ bindingAfter }: BindingOnChangeOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape(bindingAfter.fromId) as TLArrowShape | undefined\n\t\tif (!arrow) return\n\t\tarrowDidUpdate(this.editor, arrow)\n\t}\n\n\t// when the arrow itself changes\n\toverride onAfterChangeFromShape({\n\t\tshapeBefore,\n\t\tshapeAfter,\n\t\treason,\n\t}: BindingOnShapeChangeOptions<TLArrowBinding>): void {\n\t\t// When translating arrows together with their bound shapes, only x/y changes.\n\t\t// In this case, bindings remain valid and no reparenting is needed.\n\t\t// This is a significant performance optimization when moving many bound shapes.\n\t\tif (\n\t\t\treason !== 'ancestry' &&\n\t\t\tshapeBefore.parentId === shapeAfter.parentId &&\n\t\t\tshapeBefore.index === shapeAfter.index\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\tarrowDidUpdate(this.editor, shapeAfter as TLArrowShape)\n\t}\n\n\t// when the shape an arrow is bound to changes\n\toverride onAfterChangeToShape({\n\t\tbinding,\n\t\tshapeBefore,\n\t\tshapeAfter,\n\t\treason,\n\t}: BindingOnShapeChangeOptions<TLArrowBinding>): void {\n\t\tif (\n\t\t\treason !== 'ancestry' &&\n\t\t\tshapeBefore.parentId === shapeAfter.parentId &&\n\t\t\tshapeBefore.index === shapeAfter.index\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\treparentArrow(this.editor, binding.fromId)\n\t}\n\n\t// when the arrow is isolated we need to update it's x,y positions\n\toverride onBeforeIsolateFromShape({\n\t\tbinding,\n\t}: BindingOnShapeIsolateOptions<TLArrowBinding>): void {\n\t\tconst arrow = this.editor.getShape<TLArrowShape>(binding.fromId)\n\t\tif (!arrow) return\n\t\tupdateArrowTerminal({\n\t\t\teditor: this.editor,\n\t\t\tarrow,\n\t\t\tterminal: binding.props.terminal,\n\t\t})\n\t}\n}\n\nfunction reparentArrow(editor: Editor, arrowId: TLShapeId) {\n\tconst arrow = editor.getShape<TLArrowShape>(arrowId)\n\tif (!arrow) return\n\tconst bindings = getArrowBindings(editor, arrow)\n\tconst { start, end } = bindings\n\tconst startShape = start ? editor.getShape(start.toId) : undefined\n\tconst endShape = end ? editor.getShape(end.toId) : undefined\n\n\tconst parentPageId = editor.getAncestorPageId(arrow)\n\tif (!parentPageId) return\n\n\tlet nextParentId: TLParentId\n\tif (startShape && endShape) {\n\t\t// if arrow has two bindings, always parent arrow to closest common ancestor of the bindings\n\t\tnextParentId = editor.findCommonAncestor([startShape, endShape]) ?? parentPageId\n\t} else if (startShape || endShape) {\n\t\tconst bindingParentId = (startShape || endShape)?.parentId\n\t\t// If the arrow and the shape that it is bound to have the same parent, then keep that parent\n\t\tif (bindingParentId && bindingParentId === arrow.parentId) {\n\t\t\tnextParentId = arrow.parentId\n\t\t} else {\n\t\t\t// if arrow has one binding, keep arrow on its own page\n\t\t\tnextParentId = parentPageId\n\t\t}\n\t} else {\n\t\treturn\n\t}\n\n\tif (nextParentId && nextParentId !== arrow.parentId) {\n\t\teditor.reparentShapes([arrowId], nextParentId)\n\t}\n\n\tconst reparentedArrow = editor.getShape<TLArrowShape>(arrowId)\n\tif (!reparentedArrow) throw Error('no reparented arrow')\n\n\tconst startSibling = editor.getShapeNearestSibling(reparentedArrow, startShape)\n\tconst endSibling = editor.getShapeNearestSibling(reparentedArrow, endShape)\n\n\tlet highestSibling: TLShape | undefined\n\n\tif (startSibling && endSibling) {\n\t\thighestSibling = startSibling.index > endSibling.index ? startSibling : endSibling\n\t} else if (startSibling && !endSibling) {\n\t\thighestSibling = startSibling\n\t} else if (endSibling && !startSibling) {\n\t\thighestSibling = endSibling\n\t} else {\n\t\treturn\n\t}\n\n\tlet finalIndex: IndexKey\n\n\tconst higherSiblings = editor\n\t\t.getSortedChildIdsForParent(highestSibling.parentId)\n\t\t.map((id) => editor.getShape(id)!)\n\t\t.filter((sibling) => sibling.index > highestSibling!.index)\n\n\tif (higherSiblings.length) {\n\t\t// there are siblings above the highest bound sibling, we need to\n\t\t// insert between them.\n\n\t\t// if the next sibling is also a bound arrow though, we can end up\n\t\t// all fighting for the same indexes. so lets find the next\n\t\t// non-arrow sibling...\n\t\tconst nextHighestNonArrowSibling = higherSiblings.find((sibling) => sibling.type !== 'arrow')\n\n\t\tif (\n\t\t\t// ...then, if we're above the last shape we want to be above...\n\t\t\treparentedArrow.index > highestSibling.index &&\n\t\t\t// ...but below the next non-arrow sibling...\n\t\t\t(!nextHighestNonArrowSibling || reparentedArrow.index < nextHighestNonArrowSibling.index)\n\t\t) {\n\t\t\t// ...then we're already in the right place. no need to update!\n\t\t\treturn\n\t\t}\n\n\t\t// otherwise, we need to find the index between the highest sibling\n\t\t// we want to be above, and the next highest sibling we want to be\n\t\t// below:\n\t\tfinalIndex = getIndexBetween(highestSibling.index, higherSiblings[0].index)\n\t} else {\n\t\t// if there are no siblings above us, we can just get the next index:\n\t\tfinalIndex = getIndexAbove(highestSibling.index)\n\t}\n\n\tif (finalIndex !== reparentedArrow.index) {\n\t\teditor.updateShapes([{ id: arrowId, type: 'arrow', index: finalIndex }])\n\t}\n}\n\nfunction arrowDidUpdate(editor: Editor, arrow: TLArrowShape) {\n\tconst bindings = getArrowBindings(editor, arrow)\n\t// if the shape is an arrow and its bound shape is on another page\n\t// or was deleted, unbind it\n\tfor (const handle of ['start', 'end'] as const) {\n\t\tconst binding = bindings[handle]\n\t\tif (!binding) continue\n\t\tconst boundShape = editor.getShape(binding.toId)\n\t\tconst isShapeInSamePageAsArrow =\n\t\t\teditor.getAncestorPageId(arrow) === editor.getAncestorPageId(boundShape)\n\t\tif (!boundShape || !isShapeInSamePageAsArrow) {\n\t\t\tupdateArrowTerminal({ editor, arrow, terminal: handle, unbind: true })\n\t\t}\n\t}\n\n\t// always check the arrow parents\n\treparentArrow(editor, arrow.id)\n}\n\n/** @internal */\nexport function updateArrowTerminal({\n\teditor,\n\tarrow,\n\tterminal,\n\tunbind = false,\n\tuseHandle = false,\n}: {\n\teditor: Editor\n\tarrow: TLArrowShape\n\tterminal: 'start' | 'end'\n\tunbind?: boolean\n\tuseHandle?: boolean\n}) {\n\tconst info = getArrowInfo(editor, arrow)\n\tif (!info) {\n\t\tthrow new Error('expected arrow info')\n\t}\n\n\tconst startPoint = getValidTerminalPoint(\n\t\tuseHandle ? info.start.handle : info.start.point,\n\t\tarrow.props.start\n\t)\n\tconst endPoint = getValidTerminalPoint(\n\t\tuseHandle ? info.end.handle : info.end.point,\n\t\tarrow.props.end\n\t)\n\tconst point = terminal === 'start' ? startPoint : endPoint\n\n\tconst update = {\n\t\tid: arrow.id,\n\t\ttype: 'arrow',\n\t\tprops: {\n\t\t\t[terminal]: { x: point.x, y: point.y },\n\t\t\tbend: arrow.props.bend,\n\t\t},\n\t} satisfies TLShapePartial<TLArrowShape>\n\n\t// fix up the bend:\n\tif (info.type === 'arc') {\n\t\t// find the new start/end points of the resulting arrow\n\t\tconst newStart =\n\t\t\tterminal === 'start'\n\t\t\t\t? startPoint\n\t\t\t\t: getValidTerminalPoint(info.start.handle, arrow.props.start)\n\t\tconst newEnd =\n\t\t\tterminal === 'end' ? endPoint : getValidTerminalPoint(info.end.handle, arrow.props.end)\n\t\tconst newMidPoint = Vec.Med(newStart, newEnd)\n\t\tconst arrowDirection = Vec.Sub(newStart, newEnd)\n\t\tif (approximately(Vec.Len2(arrowDirection), 0)) {\n\t\t\teditor.updateShape(update)\n\t\t\tif (unbind) {\n\t\t\t\tremoveArrowBinding(editor, arrow, terminal)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\t// intersect a line segment perpendicular to the new arrow with the old arrow arc to\n\t\t// find the new mid-point\n\t\tconst lineSegment = arrowDirection\n\t\t\t.per()\n\t\t\t.uni()\n\t\t\t.mul(info.handleArc.radius * 2 * Math.sign(arrow.props.bend))\n\t\tconst targetPoint = Vec.Add(newMidPoint, lineSegment)\n\t\tif (\n\t\t\t!Vec.IsFinite(info.handleArc.center) ||\n\t\t\t!Number.isFinite(info.handleArc.radius) ||\n\t\t\t!Vec.IsFinite(targetPoint)\n\t\t) {\n\t\t\teditor.updateShape(update)\n\t\t\tif (unbind) {\n\t\t\t\tremoveArrowBinding(editor, arrow, terminal)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\t// find the intersections with the old arrow arc:\n\t\tconst intersections = intersectLineSegmentCircle(\n\t\t\tinfo.handleArc.center,\n\t\t\ttargetPoint,\n\t\t\tinfo.handleArc.center,\n\t\t\tinfo.handleArc.radius\n\t\t)\n\n\t\tif (intersections?.length) {\n\t\t\tconst intersection = intersections.reduce((closest, candidate) =>\n\t\t\t\tVec.Dist2(candidate, targetPoint) < Vec.Dist2(closest, targetPoint) ? candidate : closest\n\t\t\t)\n\t\t\tconst bend = Vec.Dist(newMidPoint, intersection) * Math.sign(arrow.props.bend)\n\t\t\t// use `approximately` to avoid endless update loops\n\t\t\tif (!approximately(bend, update.props.bend)) {\n\t\t\t\tupdate.props.bend = bend\n\t\t\t}\n\t\t}\n\t}\n\n\teditor.updateShape(update)\n\tif (unbind) {\n\t\tremoveArrowBinding(editor, arrow, terminal)\n\t}\n}\n\nfunction getValidTerminalPoint(\n\tpoint: { x: number; y: number },\n\tfallback: { x: number; y: number }\n) {\n\treturn Vec.From(Vec.IsFinite(point) ? point : fallback)\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EAKC;AAAA,EAUA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB,0BAA0B;AAK9C,MAAM,yBAAyB,YAA4B;AAAA,EACjE,OAAgB,OAAO;AAAA,EAEvB,OAAgB,QAAQ;AAAA,EACxB,OAAgB,aAAa;AAAA,EAEpB,kBAAgD;AACxD,WAAO;AAAA,MACN,WAAW;AAAA,MACX,SAAS;AAAA,MACT,kBAAkB,EAAE,GAAG,KAAK,GAAG,IAAI;AAAA,MACnC,MAAM;AAAA,IACP;AAAA,EACD;AAAA;AAAA,EAGS,cAAc,EAAE,QAAQ,GAAiD;AACjF,UAAM,QAAQ,KAAK,OAAO,SAAS,QAAQ,MAAM;AACjD,QAAI,CAAC,MAAO;AACZ,mBAAe,KAAK,QAAQ,KAAK;AAAA,EAClC;AAAA;AAAA,EAGS,cAAc,E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C,eAAO,MAAM,OAAO;AAAA,MACrB;AAAA,IACD;AAAA,EACD;AAEA,SAAO,YAAY,MAAM;AACzB,MAAI,QAAQ;AACX,uBAAmB,QAAQ,OAAO,QAAQ;AAAA,EAC3C;AACD;AAEA,SAAS,sBACR,OACA,UACC;AACD,SAAO,IAAI,KAAK,IAAI,SAAS,KAAK,IAAI,QAAQ,QAAQ;AACvD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/ui/version.ts"],
|
|
4
|
-
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '4.5.
|
|
4
|
+
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '4.5.7'\nexport const publishDates = {\n\tmajor: '2025-09-18T14:39:22.803Z',\n\tminor: '2026-03-18T11:05:13.340Z',\n\tpatch: '2026-04-03T19:09:04.689Z',\n}\n"],
|
|
5
5
|
"mappings": "AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tldraw",
|
|
3
3
|
"description": "A tiny little drawing editor.",
|
|
4
|
-
"version": "4.5.
|
|
4
|
+
"version": "4.5.7",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"@tiptap/pm": "^3.12.1",
|
|
62
62
|
"@tiptap/react": "^3.12.1",
|
|
63
63
|
"@tiptap/starter-kit": "^3.12.1",
|
|
64
|
-
"@tldraw/editor": "4.5.
|
|
65
|
-
"@tldraw/store": "4.5.
|
|
64
|
+
"@tldraw/editor": "4.5.7",
|
|
65
|
+
"@tldraw/store": "4.5.7",
|
|
66
66
|
"classnames": "^2.5.1",
|
|
67
67
|
"hotkeys-js": "^3.13.9",
|
|
68
68
|
"idb": "^7.1.1",
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
approximately,
|
|
18
18
|
arrowBindingMigrations,
|
|
19
19
|
arrowBindingProps,
|
|
20
|
-
assert,
|
|
21
20
|
getIndexAbove,
|
|
22
21
|
getIndexBetween,
|
|
23
22
|
intersectLineSegmentCircle,
|
|
@@ -235,8 +234,14 @@ export function updateArrowTerminal({
|
|
|
235
234
|
throw new Error('expected arrow info')
|
|
236
235
|
}
|
|
237
236
|
|
|
238
|
-
const startPoint =
|
|
239
|
-
|
|
237
|
+
const startPoint = getValidTerminalPoint(
|
|
238
|
+
useHandle ? info.start.handle : info.start.point,
|
|
239
|
+
arrow.props.start
|
|
240
|
+
)
|
|
241
|
+
const endPoint = getValidTerminalPoint(
|
|
242
|
+
useHandle ? info.end.handle : info.end.point,
|
|
243
|
+
arrow.props.end
|
|
244
|
+
)
|
|
240
245
|
const point = terminal === 'start' ? startPoint : endPoint
|
|
241
246
|
|
|
242
247
|
const update = {
|
|
@@ -251,30 +256,58 @@ export function updateArrowTerminal({
|
|
|
251
256
|
// fix up the bend:
|
|
252
257
|
if (info.type === 'arc') {
|
|
253
258
|
// find the new start/end points of the resulting arrow
|
|
254
|
-
const newStart =
|
|
255
|
-
|
|
259
|
+
const newStart =
|
|
260
|
+
terminal === 'start'
|
|
261
|
+
? startPoint
|
|
262
|
+
: getValidTerminalPoint(info.start.handle, arrow.props.start)
|
|
263
|
+
const newEnd =
|
|
264
|
+
terminal === 'end' ? endPoint : getValidTerminalPoint(info.end.handle, arrow.props.end)
|
|
256
265
|
const newMidPoint = Vec.Med(newStart, newEnd)
|
|
266
|
+
const arrowDirection = Vec.Sub(newStart, newEnd)
|
|
267
|
+
if (approximately(Vec.Len2(arrowDirection), 0)) {
|
|
268
|
+
editor.updateShape(update)
|
|
269
|
+
if (unbind) {
|
|
270
|
+
removeArrowBinding(editor, arrow, terminal)
|
|
271
|
+
}
|
|
272
|
+
return
|
|
273
|
+
}
|
|
257
274
|
|
|
258
275
|
// intersect a line segment perpendicular to the new arrow with the old arrow arc to
|
|
259
276
|
// find the new mid-point
|
|
260
|
-
const lineSegment =
|
|
277
|
+
const lineSegment = arrowDirection
|
|
261
278
|
.per()
|
|
262
279
|
.uni()
|
|
263
280
|
.mul(info.handleArc.radius * 2 * Math.sign(arrow.props.bend))
|
|
281
|
+
const targetPoint = Vec.Add(newMidPoint, lineSegment)
|
|
282
|
+
if (
|
|
283
|
+
!Vec.IsFinite(info.handleArc.center) ||
|
|
284
|
+
!Number.isFinite(info.handleArc.radius) ||
|
|
285
|
+
!Vec.IsFinite(targetPoint)
|
|
286
|
+
) {
|
|
287
|
+
editor.updateShape(update)
|
|
288
|
+
if (unbind) {
|
|
289
|
+
removeArrowBinding(editor, arrow, terminal)
|
|
290
|
+
}
|
|
291
|
+
return
|
|
292
|
+
}
|
|
264
293
|
|
|
265
294
|
// find the intersections with the old arrow arc:
|
|
266
295
|
const intersections = intersectLineSegmentCircle(
|
|
267
296
|
info.handleArc.center,
|
|
268
|
-
|
|
297
|
+
targetPoint,
|
|
269
298
|
info.handleArc.center,
|
|
270
299
|
info.handleArc.radius
|
|
271
300
|
)
|
|
272
301
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
302
|
+
if (intersections?.length) {
|
|
303
|
+
const intersection = intersections.reduce((closest, candidate) =>
|
|
304
|
+
Vec.Dist2(candidate, targetPoint) < Vec.Dist2(closest, targetPoint) ? candidate : closest
|
|
305
|
+
)
|
|
306
|
+
const bend = Vec.Dist(newMidPoint, intersection) * Math.sign(arrow.props.bend)
|
|
307
|
+
// use `approximately` to avoid endless update loops
|
|
308
|
+
if (!approximately(bend, update.props.bend)) {
|
|
309
|
+
update.props.bend = bend
|
|
310
|
+
}
|
|
278
311
|
}
|
|
279
312
|
}
|
|
280
313
|
|
|
@@ -283,3 +316,10 @@ export function updateArrowTerminal({
|
|
|
283
316
|
removeArrowBinding(editor, arrow, terminal)
|
|
284
317
|
}
|
|
285
318
|
}
|
|
319
|
+
|
|
320
|
+
function getValidTerminalPoint(
|
|
321
|
+
point: { x: number; y: number },
|
|
322
|
+
fallback: { x: number; y: number }
|
|
323
|
+
) {
|
|
324
|
+
return Vec.From(Vec.IsFinite(point) ? point : fallback)
|
|
325
|
+
}
|
package/src/lib/ui/version.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// This file is automatically generated by internal/scripts/refresh-assets.ts.
|
|
2
2
|
// Do not edit manually. Or do, I'm a comment, not a cop.
|
|
3
3
|
|
|
4
|
-
export const version = '4.5.
|
|
4
|
+
export const version = '4.5.7'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2025-09-18T14:39:22.803Z',
|
|
7
7
|
minor: '2026-03-18T11:05:13.340Z',
|
|
8
|
-
patch: '2026-04-
|
|
8
|
+
patch: '2026-04-03T19:09:04.689Z',
|
|
9
9
|
}
|
|
@@ -103,6 +103,57 @@ describe('Editor.deleteShapes', () => {
|
|
|
103
103
|
expect(editor.getShape(ids.box3)).toBeUndefined()
|
|
104
104
|
expect(editor.getShape(ids.box4)).toBeUndefined()
|
|
105
105
|
})
|
|
106
|
+
|
|
107
|
+
it('does not crash when deleting a bent arrow and two adjacent bound shapes', () => {
|
|
108
|
+
const leftId = createShapeId('left')
|
|
109
|
+
const rightId = createShapeId('right')
|
|
110
|
+
const bentArrowId = createShapeId('bent-arrow')
|
|
111
|
+
|
|
112
|
+
editor.createShapes([
|
|
113
|
+
{ id: leftId, type: 'geo', x: 500, y: 500, props: { w: 100, h: 100 } },
|
|
114
|
+
{ id: rightId, type: 'geo', x: 600, y: 500, props: { w: 100, h: 100 } },
|
|
115
|
+
{
|
|
116
|
+
id: bentArrowId,
|
|
117
|
+
type: 'arrow',
|
|
118
|
+
x: 550,
|
|
119
|
+
y: 550,
|
|
120
|
+
props: {
|
|
121
|
+
start: { x: 0, y: 0 },
|
|
122
|
+
end: { x: 100, y: 0 },
|
|
123
|
+
bend: -120,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
])
|
|
127
|
+
|
|
128
|
+
editor.createBindings([
|
|
129
|
+
{
|
|
130
|
+
id: createBindingId(),
|
|
131
|
+
fromId: bentArrowId,
|
|
132
|
+
toId: leftId,
|
|
133
|
+
type: 'arrow',
|
|
134
|
+
props: {
|
|
135
|
+
terminal: 'start',
|
|
136
|
+
isExact: false,
|
|
137
|
+
normalizedAnchor: { x: 1, y: 0.5 },
|
|
138
|
+
isPrecise: false,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: createBindingId(),
|
|
143
|
+
fromId: bentArrowId,
|
|
144
|
+
toId: rightId,
|
|
145
|
+
type: 'arrow',
|
|
146
|
+
props: {
|
|
147
|
+
terminal: 'end',
|
|
148
|
+
isExact: false,
|
|
149
|
+
normalizedAnchor: { x: 0, y: 0.5 },
|
|
150
|
+
isPrecise: false,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
])
|
|
154
|
+
|
|
155
|
+
expect(() => editor.deleteShapes([leftId, bentArrowId, rightId])).not.toThrow()
|
|
156
|
+
})
|
|
106
157
|
})
|
|
107
158
|
|
|
108
159
|
describe('When deleting arrows', () => {
|