tldraw 3.15.0 → 3.16.0-next.c30b1b5e551a
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.d.ts +69 -4
- package/dist-cjs/index.js +11 -2
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/canvas/TldrawCropHandles.js.map +2 -2
- package/dist-cjs/lib/defaultExternalContentHandlers.js +1 -0
- package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js +22 -36
- package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/arrowLabel.js +16 -4
- package/dist-cjs/lib/shapes/arrow/arrowLabel.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js +3 -0
- package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/line/LineShapeUtil.js +15 -1
- package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js +43 -22
- package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js +2 -15
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js +5 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js +8 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Rotating.js +8 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/Rotating.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js +8 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
- package/dist-cjs/lib/tools/selection-logic/getHitShapeOnCanvasPointerDown.js.map +2 -2
- package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js +40 -0
- package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +1 -0
- package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js.map +2 -2
- package/dist-cjs/lib/ui/context/actions.js +14 -7
- package/dist-cjs/lib/ui/context/actions.js.map +2 -2
- package/dist-cjs/lib/ui/context/events.js.map +1 -1
- package/dist-cjs/lib/ui/hooks/menu-hooks.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
- package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +4 -0
- package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +2 -2
- package/dist-cjs/lib/ui/kbd-utils.js +2 -1
- package/dist-cjs/lib/ui/kbd-utils.js.map +2 -2
- package/dist-cjs/lib/ui/version.js +3 -3
- package/dist-cjs/lib/ui/version.js.map +1 -1
- package/dist-cjs/lib/utils/excalidraw/putExcalidrawContent.js +1 -1
- package/dist-cjs/lib/utils/excalidraw/putExcalidrawContent.js.map +2 -2
- package/dist-cjs/lib/utils/tldr/buildFromV1Document.js +3 -2
- package/dist-cjs/lib/utils/tldr/buildFromV1Document.js.map +2 -2
- package/dist-esm/index.d.mts +69 -4
- package/dist-esm/index.mjs +16 -3
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/canvas/TldrawCropHandles.mjs.map +2 -2
- package/dist-esm/lib/defaultExternalContentHandlers.mjs +1 -0
- package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +24 -36
- package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/arrowLabel.mjs +19 -5
- package/dist-esm/lib/shapes/arrow/arrowLabel.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs +3 -0
- package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +15 -1
- package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs +43 -22
- package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs +2 -15
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs +5 -0
- package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs +8 -0
- package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Rotating.mjs +8 -0
- package/dist-esm/lib/tools/SelectTool/childStates/Rotating.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs +8 -0
- package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
- package/dist-esm/lib/tools/selection-logic/getHitShapeOnCanvasPointerDown.mjs.map +2 -2
- package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs +40 -0
- package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs +1 -0
- package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs.map +2 -2
- package/dist-esm/lib/ui/context/actions.mjs +14 -7
- package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
- package/dist-esm/lib/ui/context/events.mjs.map +1 -1
- package/dist-esm/lib/ui/hooks/menu-hooks.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +4 -0
- package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +2 -2
- package/dist-esm/lib/ui/kbd-utils.mjs +2 -1
- package/dist-esm/lib/ui/kbd-utils.mjs.map +2 -2
- package/dist-esm/lib/ui/version.mjs +3 -3
- package/dist-esm/lib/ui/version.mjs.map +1 -1
- package/dist-esm/lib/utils/excalidraw/putExcalidrawContent.mjs +1 -1
- package/dist-esm/lib/utils/excalidraw/putExcalidrawContent.mjs.map +2 -2
- package/dist-esm/lib/utils/tldr/buildFromV1Document.mjs +3 -2
- package/dist-esm/lib/utils/tldr/buildFromV1Document.mjs.map +2 -2
- package/package.json +3 -3
- package/src/index.ts +9 -1
- package/src/lib/canvas/TldrawCropHandles.tsx +2 -0
- package/src/lib/defaultExternalContentHandlers.ts +2 -1
- package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +5 -5
- package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +25 -39
- package/src/lib/shapes/arrow/arrowLabel.ts +23 -3
- package/src/lib/shapes/arrow/toolStates/Pointing.tsx +3 -0
- package/src/lib/shapes/line/LineShapeUtil.tsx +19 -2
- package/src/lib/tools/SelectTool/childStates/DraggingHandle.tsx +54 -30
- package/src/lib/tools/SelectTool/childStates/Idle.ts +2 -24
- package/src/lib/tools/SelectTool/childStates/PointingShape.ts +7 -0
- package/src/lib/tools/SelectTool/childStates/Resizing.ts +12 -1
- package/src/lib/tools/SelectTool/childStates/Rotating.ts +11 -0
- package/src/lib/tools/SelectTool/childStates/Translating.ts +11 -0
- package/src/lib/tools/selection-logic/getHitShapeOnCanvasPointerDown.ts +1 -0
- package/src/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.tsx +32 -0
- package/src/lib/ui/components/Toolbar/ToggleToolLockedButton.tsx +3 -1
- package/src/lib/ui/components/primitives/TldrawUiSlider.tsx +1 -0
- package/src/lib/ui/context/actions.tsx +14 -7
- package/src/lib/ui/context/events.tsx +2 -2
- package/src/lib/ui/hooks/menu-hooks.ts +1 -0
- package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +4 -0
- package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +4 -0
- package/src/lib/ui/kbd-utils.ts +2 -1
- package/src/lib/ui/version.ts +3 -3
- package/src/lib/utils/excalidraw/__snapshots__/putExcalidrawContent.test.tsx.snap +16 -2
- package/src/lib/utils/excalidraw/putExcalidrawContent.ts +1 -1
- package/src/lib/utils/tldr/__snapshots__/buildFromV1Document.test.ts.snap +24 -3
- package/src/lib/utils/tldr/buildFromV1Document.ts +2 -1
- package/src/test/SelectTool.test.ts +37 -11
- package/src/test/commands/deletePage.test.ts +84 -1
- package/src/test/shapeutils.test.ts +394 -45
- package/tldraw.css +4 -23
|
@@ -9,13 +9,17 @@ import {
|
|
|
9
9
|
Polygon2d,
|
|
10
10
|
Polyline2d,
|
|
11
11
|
TLArrowShape,
|
|
12
|
+
TLShape,
|
|
12
13
|
Vec,
|
|
13
14
|
VecLike,
|
|
14
15
|
clamp,
|
|
15
16
|
createComputedCache,
|
|
16
17
|
exhaustiveSwitchError,
|
|
17
18
|
getChangedKeys,
|
|
19
|
+
pointInPolygon,
|
|
20
|
+
toRichText,
|
|
18
21
|
} from '@tldraw/editor'
|
|
22
|
+
import { isEmptyRichText, renderHtmlFromRichTextForMeasurement } from '../../utils/text/richText'
|
|
19
23
|
import {
|
|
20
24
|
ARROW_LABEL_FONT_SIZES,
|
|
21
25
|
ARROW_LABEL_PADDING,
|
|
@@ -59,14 +63,18 @@ const labelSizeCache = createComputedCache(
|
|
|
59
63
|
|
|
60
64
|
const bodyGeom = getArrowBodyGeometry(editor, shape)
|
|
61
65
|
// We use 'i' as a default label to measure against as a minimum width.
|
|
62
|
-
const
|
|
66
|
+
const isEmpty = isEmptyRichText(shape.props.richText)
|
|
67
|
+
const html = renderHtmlFromRichTextForMeasurement(
|
|
68
|
+
editor,
|
|
69
|
+
isEmpty ? toRichText('i') : shape.props.richText
|
|
70
|
+
)
|
|
63
71
|
|
|
64
72
|
const bodyBounds = bodyGeom.bounds
|
|
65
73
|
|
|
66
74
|
const fontSize = getArrowLabelFontSize(shape)
|
|
67
75
|
|
|
68
76
|
// First we measure the text with no constraints
|
|
69
|
-
const { w, h } = editor.textMeasure.
|
|
77
|
+
const { w, h } = editor.textMeasure.measureHtml(html, {
|
|
70
78
|
...TEXT_PROPS,
|
|
71
79
|
fontFamily: FONT_FAMILIES[shape.props.font],
|
|
72
80
|
fontSize,
|
|
@@ -96,7 +104,7 @@ const labelSizeCache = createComputedCache(
|
|
|
96
104
|
}
|
|
97
105
|
|
|
98
106
|
if (shouldSquish) {
|
|
99
|
-
const { w: squishedWidth, h: squishedHeight } = editor.textMeasure.
|
|
107
|
+
const { w: squishedWidth, h: squishedHeight } = editor.textMeasure.measureHtml(html, {
|
|
100
108
|
...TEXT_PROPS,
|
|
101
109
|
fontFamily: FONT_FAMILIES[shape.props.font],
|
|
102
110
|
fontSize,
|
|
@@ -292,3 +300,15 @@ export function getArrowLabelDefaultPosition(editor: Editor, shape: TLArrowShape
|
|
|
292
300
|
exhaustiveSwitchError(info, 'type')
|
|
293
301
|
}
|
|
294
302
|
}
|
|
303
|
+
|
|
304
|
+
/** @internal */
|
|
305
|
+
export function isOverArrowLabel(editor: Editor, shape: TLShape) {
|
|
306
|
+
if (!editor.isShapeOfType<TLArrowShape>(shape, 'arrow')) return false
|
|
307
|
+
|
|
308
|
+
const pointInShapeSpace = editor.getPointInShapeSpace(shape, editor.inputs.currentPagePoint)
|
|
309
|
+
// How should we handle multiple labels? Do shapes ever have multiple labels?
|
|
310
|
+
const labelGeometry = editor.getShapeGeometry<Group2d>(shape).children[1]
|
|
311
|
+
// Knowing what we know about arrows... if the shape has no text in its label,
|
|
312
|
+
// then the label geometry should not be there.
|
|
313
|
+
return labelGeometry && pointInPolygon(pointInShapeSpace, labelGeometry.vertices)
|
|
314
|
+
}
|
|
@@ -118,6 +118,7 @@ export class Pointing extends StateNode {
|
|
|
118
118
|
const change = util.onHandleDrag?.(shape, {
|
|
119
119
|
handle: { ...startHandle, x: 0, y: 0 },
|
|
120
120
|
isPrecise: true,
|
|
121
|
+
isCreatingShape: true,
|
|
121
122
|
initial: initial,
|
|
122
123
|
})
|
|
123
124
|
|
|
@@ -145,6 +146,7 @@ export class Pointing extends StateNode {
|
|
|
145
146
|
const change = util.onHandleDrag?.(shape, {
|
|
146
147
|
handle: { ...startHandle, x: 0, y: 0 },
|
|
147
148
|
isPrecise: this.isPrecise,
|
|
149
|
+
isCreatingShape: true,
|
|
148
150
|
initial: initial,
|
|
149
151
|
})
|
|
150
152
|
|
|
@@ -162,6 +164,7 @@ export class Pointing extends StateNode {
|
|
|
162
164
|
const change = util.onHandleDrag?.(this.editor.getShape(shape)!, {
|
|
163
165
|
handle: { ...endHandle, x: point.x, y: point.y },
|
|
164
166
|
isPrecise: false,
|
|
167
|
+
isCreatingShape: true,
|
|
165
168
|
initial: initial,
|
|
166
169
|
})
|
|
167
170
|
|
|
@@ -145,8 +145,6 @@ export class LineShapeUtil extends ShapeUtil<TLLineShape> {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
override onHandleDrag(shape: TLLineShape, { handle }: TLHandleDragInfo<TLLineShape>) {
|
|
148
|
-
// we should only ever be dragging vertex handles
|
|
149
|
-
if (handle.type !== 'vertex') return
|
|
150
148
|
const newPoint = maybeSnapToGrid(new Vec(handle.x, handle.y), this.editor)
|
|
151
149
|
return {
|
|
152
150
|
...shape,
|
|
@@ -160,6 +158,25 @@ export class LineShapeUtil extends ShapeUtil<TLLineShape> {
|
|
|
160
158
|
}
|
|
161
159
|
}
|
|
162
160
|
|
|
161
|
+
override onHandleDragStart(shape: TLLineShape, { handle }: TLHandleDragInfo<TLLineShape>) {
|
|
162
|
+
// For line shapes, if we're dragging a "create" handle, then
|
|
163
|
+
// create a new vertex handle at that point; and make this handle
|
|
164
|
+
// the handle that we're dragging.
|
|
165
|
+
if (handle.type === 'create') {
|
|
166
|
+
return {
|
|
167
|
+
...shape,
|
|
168
|
+
props: {
|
|
169
|
+
...shape.props,
|
|
170
|
+
points: {
|
|
171
|
+
...shape.props.points,
|
|
172
|
+
[handle.index]: { id: handle.index, index: handle.index, x: handle.x, y: handle.y },
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
|
|
163
180
|
component(shape: TLLineShape) {
|
|
164
181
|
return (
|
|
165
182
|
<SVGContainer style={{ minWidth: 50, minHeight: 50 }}>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Mat,
|
|
2
3
|
StateNode,
|
|
3
4
|
TLArrowShape,
|
|
4
5
|
TLHandle,
|
|
@@ -26,20 +27,20 @@ export type DraggingHandleInfo = TLPointerEventInfo & {
|
|
|
26
27
|
export class DraggingHandle extends StateNode {
|
|
27
28
|
static override id = 'dragging_handle'
|
|
28
29
|
|
|
29
|
-
shapeId
|
|
30
|
-
initialHandle
|
|
31
|
-
initialAdjacentHandle
|
|
32
|
-
initialPagePoint
|
|
30
|
+
shapeId!: TLShapeId
|
|
31
|
+
initialHandle!: TLHandle
|
|
32
|
+
initialAdjacentHandle!: TLHandle | null
|
|
33
|
+
initialPagePoint!: Vec
|
|
33
34
|
|
|
34
|
-
markId
|
|
35
|
-
initialPageTransform
|
|
36
|
-
initialPageRotation
|
|
35
|
+
markId!: string
|
|
36
|
+
initialPageTransform!: Mat
|
|
37
|
+
initialPageRotation!: number
|
|
37
38
|
|
|
38
|
-
info
|
|
39
|
+
info!: DraggingHandleInfo
|
|
39
40
|
|
|
40
41
|
isPrecise = false
|
|
41
|
-
isPreciseId
|
|
42
|
-
pointingId
|
|
42
|
+
isPreciseId: TLShapeId | null = null
|
|
43
|
+
pointingId: TLShapeId | null = null
|
|
43
44
|
|
|
44
45
|
override onEnter(info: DraggingHandleInfo) {
|
|
45
46
|
const { shape, isCreating, creatingMarkId, handle } = info
|
|
@@ -66,26 +67,6 @@ export class DraggingHandle extends StateNode {
|
|
|
66
67
|
|
|
67
68
|
this.initialHandle = structuredClone(handle)
|
|
68
69
|
|
|
69
|
-
if (this.editor.isShapeOfType<TLLineShape>(shape, 'line')) {
|
|
70
|
-
// For line shapes, if we're dragging a "create" handle, then
|
|
71
|
-
// create a new vertex handle at that point; and make this handle
|
|
72
|
-
// the handle that we're dragging.
|
|
73
|
-
if (this.initialHandle.type === 'create') {
|
|
74
|
-
this.editor.updateShape({
|
|
75
|
-
...shape,
|
|
76
|
-
props: {
|
|
77
|
-
points: {
|
|
78
|
-
...shape.props.points,
|
|
79
|
-
[handle.index]: { id: handle.index, index: handle.index, x: handle.x, y: handle.y },
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
})
|
|
83
|
-
const handlesAfter = this.editor.getShapeHandles(shape)!
|
|
84
|
-
const handleAfter = handlesAfter.find((h) => h.index === handle.index)!
|
|
85
|
-
this.initialHandle = structuredClone(handleAfter)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
70
|
this.initialPageTransform = this.editor.getShapePageTransform(shape)!
|
|
90
71
|
this.initialPageRotation = this.initialPageTransform.rotation()
|
|
91
72
|
this.initialPagePoint = this.editor.inputs.originPagePoint.clone()
|
|
@@ -135,6 +116,19 @@ export class DraggingHandle extends StateNode {
|
|
|
135
116
|
}
|
|
136
117
|
// -->
|
|
137
118
|
|
|
119
|
+
// Call onHandleDragStart callback
|
|
120
|
+
const handleDragInfo = {
|
|
121
|
+
handle: this.initialHandle,
|
|
122
|
+
isPrecise: this.isPrecise,
|
|
123
|
+
isCreatingShape: !!this.info.isCreating,
|
|
124
|
+
initial: shape,
|
|
125
|
+
}
|
|
126
|
+
const util = this.editor.getShapeUtil(shape)
|
|
127
|
+
const startChanges = util.onHandleDragStart?.(shape, handleDragInfo)
|
|
128
|
+
if (startChanges) {
|
|
129
|
+
this.editor.updateShapes([{ ...startChanges, id: shape.id, type: shape.type }])
|
|
130
|
+
}
|
|
131
|
+
|
|
138
132
|
this.update()
|
|
139
133
|
|
|
140
134
|
this.editor.select(this.shapeId)
|
|
@@ -204,6 +198,22 @@ export class DraggingHandle extends StateNode {
|
|
|
204
198
|
this.editor.snaps.clearIndicators()
|
|
205
199
|
kickoutOccludedShapes(this.editor, [this.shapeId])
|
|
206
200
|
|
|
201
|
+
// Call onHandleDragEnd callback before state transitions
|
|
202
|
+
const shape = this.editor.getShape(this.shapeId)
|
|
203
|
+
if (shape) {
|
|
204
|
+
const util = this.editor.getShapeUtil(shape)
|
|
205
|
+
const handleDragInfo = {
|
|
206
|
+
handle: this.initialHandle,
|
|
207
|
+
isPrecise: this.isPrecise,
|
|
208
|
+
isCreatingShape: !!this.info.isCreating,
|
|
209
|
+
initial: this.info.shape,
|
|
210
|
+
}
|
|
211
|
+
const endChanges = util.onHandleDragEnd?.(shape, handleDragInfo)
|
|
212
|
+
if (endChanges) {
|
|
213
|
+
this.editor.updateShapes([{ ...endChanges, id: shape.id, type: shape.type }])
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
207
217
|
const { onInteractionEnd } = this.info
|
|
208
218
|
if (this.editor.getInstanceState().isToolLocked && onInteractionEnd) {
|
|
209
219
|
// Return to the tool that was active before this one,
|
|
@@ -216,6 +226,19 @@ export class DraggingHandle extends StateNode {
|
|
|
216
226
|
}
|
|
217
227
|
|
|
218
228
|
private cancel() {
|
|
229
|
+
// Call onHandleDragCancel callback before bailing to mark
|
|
230
|
+
const shape = this.editor.getShape(this.shapeId)
|
|
231
|
+
if (shape) {
|
|
232
|
+
const util = this.editor.getShapeUtil(shape)
|
|
233
|
+
const handleDragInfo = {
|
|
234
|
+
handle: this.initialHandle,
|
|
235
|
+
isPrecise: this.isPrecise,
|
|
236
|
+
isCreatingShape: !!this.info.isCreating,
|
|
237
|
+
initial: this.info.shape,
|
|
238
|
+
}
|
|
239
|
+
util.onHandleDragCancel?.(shape, handleDragInfo)
|
|
240
|
+
}
|
|
241
|
+
|
|
219
242
|
this.editor.bailToMark(this.markId)
|
|
220
243
|
this.editor.snaps.clearIndicators()
|
|
221
244
|
|
|
@@ -284,6 +307,7 @@ export class DraggingHandle extends StateNode {
|
|
|
284
307
|
const changes = util.onHandleDrag?.(shape, {
|
|
285
308
|
handle: nextHandle,
|
|
286
309
|
isPrecise: this.isPrecise || altKey,
|
|
310
|
+
isCreatingShape: !!this.info.isCreating,
|
|
287
311
|
initial: initial,
|
|
288
312
|
})
|
|
289
313
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Editor,
|
|
3
|
-
Group2d,
|
|
4
3
|
StateNode,
|
|
5
4
|
TLAdjacentDirection,
|
|
6
|
-
TLArrowShape,
|
|
7
5
|
TLClickEventInfo,
|
|
8
6
|
TLGroupShape,
|
|
9
7
|
TLKeyboardEventInfo,
|
|
@@ -18,6 +16,7 @@ import {
|
|
|
18
16
|
pointInPolygon,
|
|
19
17
|
toRichText,
|
|
20
18
|
} from '@tldraw/editor'
|
|
19
|
+
import { isOverArrowLabel } from '../../../shapes/arrow/arrowLabel'
|
|
21
20
|
import { getHitShapeOnCanvasPointerDown } from '../../selection-logic/getHitShapeOnCanvasPointerDown'
|
|
22
21
|
import { getShouldEnterCropMode } from '../../selection-logic/getShouldEnterCropModeOnPointerDown'
|
|
23
22
|
import { selectOnCanvasPointerUp } from '../../selection-logic/selectOnCanvasPointerUp'
|
|
@@ -98,12 +97,6 @@ export class Idle extends StateNode {
|
|
|
98
97
|
case 'shape': {
|
|
99
98
|
const { shape } = info
|
|
100
99
|
|
|
101
|
-
if (this.isOverArrowLabelTest(shape)) {
|
|
102
|
-
// We're moving the label on a shape.
|
|
103
|
-
this.parent.transition('pointing_arrow_label', info)
|
|
104
|
-
break
|
|
105
|
-
}
|
|
106
|
-
|
|
107
100
|
if (this.editor.isShapeOrAncestorLocked(shape)) {
|
|
108
101
|
this.parent.transition('pointing_canvas', info)
|
|
109
102
|
break
|
|
@@ -595,22 +588,7 @@ export class Idle extends StateNode {
|
|
|
595
588
|
isOverArrowLabelTest(shape: TLShape | undefined) {
|
|
596
589
|
if (!shape) return false
|
|
597
590
|
|
|
598
|
-
|
|
599
|
-
if (this.editor.isShapeOfType<TLArrowShape>(shape, 'arrow')) {
|
|
600
|
-
const pointInShapeSpace = this.editor.getPointInShapeSpace(
|
|
601
|
-
shape,
|
|
602
|
-
this.editor.inputs.currentPagePoint
|
|
603
|
-
)
|
|
604
|
-
// How should we handle multiple labels? Do shapes ever have multiple labels?
|
|
605
|
-
const labelGeometry = this.editor.getShapeGeometry<Group2d>(shape).children[1]
|
|
606
|
-
// Knowing what we know about arrows... if the shape has no text in its label,
|
|
607
|
-
// then the label geometry should not be there.
|
|
608
|
-
if (labelGeometry && pointInPolygon(pointInShapeSpace, labelGeometry.vertices)) {
|
|
609
|
-
return true
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
return false
|
|
591
|
+
return isOverArrowLabel(this.editor, shape)
|
|
614
592
|
}
|
|
615
593
|
|
|
616
594
|
handleDoubleClickOnCanvas(info: TLClickEventInfo) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StateNode, TLPointerEventInfo, TLShape } from '@tldraw/editor'
|
|
2
|
+
import { isOverArrowLabel } from '../../../shapes/arrow/arrowLabel'
|
|
2
3
|
import { getTextLabels } from '../../../utils/shapes/shapes'
|
|
3
4
|
|
|
4
5
|
export class PointingShape extends StateNode {
|
|
@@ -210,6 +211,12 @@ export class PointingShape extends StateNode {
|
|
|
210
211
|
|
|
211
212
|
override onPointerMove(info: TLPointerEventInfo) {
|
|
212
213
|
if (this.editor.inputs.isDragging) {
|
|
214
|
+
if (isOverArrowLabel(this.editor, this.hitShape)) {
|
|
215
|
+
// We're moving the label on a shape.
|
|
216
|
+
this.parent.transition('pointing_arrow_label', { ...info, shape: this.hitShape })
|
|
217
|
+
return
|
|
218
|
+
}
|
|
219
|
+
|
|
213
220
|
if (this.didCtrlOnEnter) {
|
|
214
221
|
this.parent.transition('brushing', info)
|
|
215
222
|
} else {
|
|
@@ -122,8 +122,19 @@ export class Resizing extends StateNode {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
private cancel() {
|
|
125
|
-
//
|
|
125
|
+
// Call onResizeCancel callback before resetting
|
|
126
|
+
const { shapeSnapshots } = this.snapshot
|
|
127
|
+
|
|
128
|
+
shapeSnapshots.forEach(({ shape }) => {
|
|
129
|
+
const current = this.editor.getShape(shape.id)
|
|
130
|
+
if (current) {
|
|
131
|
+
const util = this.editor.getShapeUtil(shape)
|
|
132
|
+
util.onResizeCancel?.(shape, current)
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
|
|
126
136
|
this.editor.bailToMark(this.markId)
|
|
137
|
+
|
|
127
138
|
if (this.info.onInteractionEnd) {
|
|
128
139
|
this.editor.setCurrentTool(this.info.onInteractionEnd, {})
|
|
129
140
|
} else {
|
|
@@ -109,6 +109,17 @@ export class Rotating extends StateNode {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
private cancel() {
|
|
112
|
+
// Call onRotateCancel callback before bailing to mark
|
|
113
|
+
const { shapeSnapshots } = this.snapshot
|
|
114
|
+
|
|
115
|
+
shapeSnapshots.forEach(({ shape }) => {
|
|
116
|
+
const current = this.editor.getShape(shape.id)
|
|
117
|
+
if (current) {
|
|
118
|
+
const util = this.editor.getShapeUtil(shape)
|
|
119
|
+
util.onRotateCancel?.(shape, current)
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
|
|
112
123
|
this.editor.bailToMark(this.markId)
|
|
113
124
|
if (this.info.onInteractionEnd) {
|
|
114
125
|
this.editor.setCurrentTool(this.info.onInteractionEnd, this.info)
|
|
@@ -203,6 +203,17 @@ export class Translating extends StateNode {
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
private cancel() {
|
|
206
|
+
// Call onTranslateCancel callback before resetting
|
|
207
|
+
const { movingShapes } = this.snapshot
|
|
208
|
+
|
|
209
|
+
movingShapes.forEach((shape) => {
|
|
210
|
+
const current = this.editor.getShape(shape.id)
|
|
211
|
+
if (current) {
|
|
212
|
+
const util = this.editor.getShapeUtil(shape)
|
|
213
|
+
util.onTranslateCancel?.(shape, current)
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
|
|
206
217
|
this.reset()
|
|
207
218
|
if (this.info.onInteractionEnd) {
|
|
208
219
|
this.editor.setCurrentTool(this.info.onInteractionEnd)
|
package/src/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.tsx
CHANGED
|
@@ -210,6 +210,38 @@ export function DefaultKeyboardShortcutsDialogContent() {
|
|
|
210
210
|
/* do nothing */
|
|
211
211
|
}}
|
|
212
212
|
/>
|
|
213
|
+
<TldrawUiMenuItem
|
|
214
|
+
id="a11y-rotate-shape-cw"
|
|
215
|
+
label="a11y.rotate-shape-cw"
|
|
216
|
+
kbd="shift+﹥"
|
|
217
|
+
onSelect={() => {
|
|
218
|
+
/* do nothing */
|
|
219
|
+
}}
|
|
220
|
+
/>
|
|
221
|
+
<TldrawUiMenuItem
|
|
222
|
+
id="a11y-rotate-shape-cw-fine"
|
|
223
|
+
label="a11y.rotate-shape-cw-fine"
|
|
224
|
+
kbd="shift+alt+﹥"
|
|
225
|
+
onSelect={() => {
|
|
226
|
+
/* do nothing */
|
|
227
|
+
}}
|
|
228
|
+
/>
|
|
229
|
+
<TldrawUiMenuItem
|
|
230
|
+
id="a11y-rotate-shape-ccw"
|
|
231
|
+
label="a11y.rotate-shape-ccw"
|
|
232
|
+
kbd="shift+﹤"
|
|
233
|
+
onSelect={() => {
|
|
234
|
+
/* do nothing */
|
|
235
|
+
}}
|
|
236
|
+
/>
|
|
237
|
+
<TldrawUiMenuItem
|
|
238
|
+
id="a11y-rotate-shape-ccw-fine"
|
|
239
|
+
label="a11y.rotate-shape-ccw-fine"
|
|
240
|
+
kbd="shift+alt+﹤"
|
|
241
|
+
onSelect={() => {
|
|
242
|
+
/* do nothing */
|
|
243
|
+
}}
|
|
244
|
+
/>
|
|
213
245
|
<TldrawUiMenuActionItem actionId="enlarge-shapes" />
|
|
214
246
|
<TldrawUiMenuActionItem actionId="shrink-shapes" />
|
|
215
247
|
<TldrawUiMenuActionItem actionId="a11y-repeat-shape-announce" />
|
|
@@ -6,10 +6,12 @@ import { useTranslation } from '../../hooks/useTranslation/useTranslation'
|
|
|
6
6
|
import { TldrawUiButton } from '../primitives/Button/TldrawUiButton'
|
|
7
7
|
import { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/** @public */
|
|
10
|
+
export interface ToggleToolLockedButtonProps {
|
|
10
11
|
activeToolId?: string
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
/** @public @react */
|
|
13
15
|
export function ToggleToolLockedButton({ activeToolId }: ToggleToolLockedButtonProps) {
|
|
14
16
|
const editor = useEditor()
|
|
15
17
|
const breakpoint = useBreakpoint()
|
|
@@ -86,6 +86,7 @@ export const TldrawUiSlider = React.forwardRef<HTMLDivElement, TLUiSliderProps>(
|
|
|
86
86
|
aria-valuemin={(min ?? 0) * ariaValueModifier}
|
|
87
87
|
aria-valuenow={value * ariaValueModifier}
|
|
88
88
|
aria-valuemax={steps * ariaValueModifier}
|
|
89
|
+
aria-label={title + ' — ' + msg(label as TLUiTranslationKey)}
|
|
89
90
|
className="tlui-slider__thumb"
|
|
90
91
|
dir="ltr"
|
|
91
92
|
ref={ref}
|
|
@@ -1037,17 +1037,20 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
1037
1037
|
id: 'rotate-cw',
|
|
1038
1038
|
label: 'action.rotate-cw',
|
|
1039
1039
|
icon: 'rotate-cw',
|
|
1040
|
+
kbd: 'shift+.,shift+alt+.',
|
|
1040
1041
|
onSelect(source) {
|
|
1041
1042
|
if (!canApplySelectionAction()) return
|
|
1042
1043
|
if (mustGoBackToSelectToolFirst()) return
|
|
1043
1044
|
|
|
1044
|
-
|
|
1045
|
+
const isFine = editor.inputs.altKey
|
|
1046
|
+
trackEvent('rotate-cw', { source, fine: isFine })
|
|
1045
1047
|
editor.markHistoryStoppingPoint('rotate-cw')
|
|
1046
1048
|
editor.run(() => {
|
|
1047
|
-
const
|
|
1048
|
-
const
|
|
1049
|
+
const rotation = HALF_PI / (isFine ? 96 : 6)
|
|
1050
|
+
const offset = editor.getSelectionRotation() % rotation
|
|
1051
|
+
const dontUseOffset = approximately(offset, 0) || approximately(offset, rotation)
|
|
1049
1052
|
const selectedShapeIds = editor.getSelectedShapeIds()
|
|
1050
|
-
editor.rotateShapesBy(selectedShapeIds,
|
|
1053
|
+
editor.rotateShapesBy(selectedShapeIds, rotation - (dontUseOffset ? 0 : offset))
|
|
1051
1054
|
kickoutOccludedShapes(editor, selectedShapeIds)
|
|
1052
1055
|
})
|
|
1053
1056
|
},
|
|
@@ -1056,17 +1059,21 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
1056
1059
|
id: 'rotate-ccw',
|
|
1057
1060
|
label: 'action.rotate-ccw',
|
|
1058
1061
|
icon: 'rotate-ccw',
|
|
1062
|
+
// omg double comma
|
|
1063
|
+
kbd: 'shift+,,shift+alt+,',
|
|
1059
1064
|
onSelect(source) {
|
|
1060
1065
|
if (!canApplySelectionAction()) return
|
|
1061
1066
|
if (mustGoBackToSelectToolFirst()) return
|
|
1062
1067
|
|
|
1063
|
-
|
|
1068
|
+
const isFine = editor.inputs.altKey
|
|
1069
|
+
trackEvent('rotate-ccw', { source, fine: isFine })
|
|
1064
1070
|
editor.markHistoryStoppingPoint('rotate-ccw')
|
|
1065
1071
|
editor.run(() => {
|
|
1066
|
-
const
|
|
1072
|
+
const rotation = HALF_PI / (isFine ? 96 : 6)
|
|
1073
|
+
const offset = editor.getSelectionRotation() % rotation
|
|
1067
1074
|
const offsetCloseToZero = approximately(offset, 0)
|
|
1068
1075
|
const selectedShapeIds = editor.getSelectedShapeIds()
|
|
1069
|
-
editor.rotateShapesBy(selectedShapeIds, offsetCloseToZero ? -
|
|
1076
|
+
editor.rotateShapesBy(selectedShapeIds, offsetCloseToZero ? -rotation : -offset)
|
|
1070
1077
|
kickoutOccludedShapes(editor, selectedShapeIds)
|
|
1071
1078
|
})
|
|
1072
1079
|
},
|
|
@@ -76,8 +76,8 @@ export interface TLUiEventMap {
|
|
|
76
76
|
'delete-shapes': null
|
|
77
77
|
'select-all-shapes': null
|
|
78
78
|
'select-none-shapes': null
|
|
79
|
-
'rotate-ccw':
|
|
80
|
-
'rotate-cw':
|
|
79
|
+
'rotate-ccw': { fine: boolean }
|
|
80
|
+
'rotate-cw': { fine: boolean }
|
|
81
81
|
'zoom-in': { towardsCursor: boolean }
|
|
82
82
|
'zoom-out': { towardsCursor: boolean }
|
|
83
83
|
'zoom-to-fit': null
|
|
@@ -123,6 +123,7 @@ export function useAnySelectedShapesCount(min?: number, max?: number) {
|
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
125
|
* Returns true if the number of UNLOCKED selected shapes is at least min or at most max.
|
|
126
|
+
* @public
|
|
126
127
|
*/
|
|
127
128
|
export function useUnlockedSelectedShapesCount(min?: number, max?: number) {
|
|
128
129
|
const editor = useEditor()
|
|
@@ -286,6 +286,10 @@ export type TLUiTranslationKey =
|
|
|
286
286
|
| 'a11y.repeat-shape'
|
|
287
287
|
| 'a11y.move-shape'
|
|
288
288
|
| 'a11y.move-shape-faster'
|
|
289
|
+
| 'a11y.rotate-shape-cw'
|
|
290
|
+
| 'a11y.rotate-shape-ccw'
|
|
291
|
+
| 'a11y.rotate-shape-cw-fine'
|
|
292
|
+
| 'a11y.rotate-shape-ccw-fine'
|
|
289
293
|
| 'a11y.enlarge-shape'
|
|
290
294
|
| 'a11y.shrink-shape'
|
|
291
295
|
| 'a11y.pan-camera'
|
|
@@ -287,6 +287,10 @@ export const DEFAULT_TRANSLATION = {
|
|
|
287
287
|
'a11y.repeat-shape': 'Repeat shape',
|
|
288
288
|
'a11y.move-shape': 'Move shape',
|
|
289
289
|
'a11y.move-shape-faster': 'Move shape faster',
|
|
290
|
+
'a11y.rotate-shape-cw': 'Rotate shape clockwise',
|
|
291
|
+
'a11y.rotate-shape-ccw': 'Rotate shape counterclockwise',
|
|
292
|
+
'a11y.rotate-shape-cw-fine': 'Rotate shape clockwise (fine)',
|
|
293
|
+
'a11y.rotate-shape-ccw-fine': 'Rotate shape counterclockwise (fine)',
|
|
290
294
|
'a11y.enlarge-shape': 'Enlarge shape',
|
|
291
295
|
'a11y.shrink-shape': 'Shrink shape',
|
|
292
296
|
'a11y.pan-camera': 'Pan camera',
|
package/src/lib/ui/kbd-utils.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { tlenv } from '@tldraw/editor'
|
|
|
2
2
|
|
|
3
3
|
// N.B. We rework these Windows placeholders down below.
|
|
4
4
|
const cmdKey = tlenv.isDarwin ? '⌘' : '__CTRL__'
|
|
5
|
+
const ctrlKey = tlenv.isDarwin ? '⌃' : '__CTRL__'
|
|
5
6
|
const altKey = tlenv.isDarwin ? '⌥' : '__ALT__'
|
|
6
7
|
|
|
7
8
|
/** @public */
|
|
@@ -19,7 +20,7 @@ export function kbd(str: string) {
|
|
|
19
20
|
? s.replace(/[[\]]/g, '')
|
|
20
21
|
: s
|
|
21
22
|
.replace(/cmd\+/g, cmdKey)
|
|
22
|
-
.replace(/ctrl\+/g,
|
|
23
|
+
.replace(/ctrl\+/g, ctrlKey)
|
|
23
24
|
.replace(/alt\+/g, altKey)
|
|
24
25
|
.replace(/shift\+/g, '⇧')
|
|
25
26
|
// Backwards compatibility with the old system.
|
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 = '3.
|
|
4
|
+
export const version = '3.16.0-next.c30b1b5e551a'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2024-09-13T14:36:29.063Z',
|
|
7
|
-
minor: '2025-07-30T09:
|
|
8
|
-
patch: '2025-07-30T09:
|
|
7
|
+
minor: '2025-07-30T09:52:11.036Z',
|
|
8
|
+
patch: '2025-07-30T09:52:11.036Z',
|
|
9
9
|
}
|
|
@@ -149,13 +149,20 @@ exports[`putExcalidrawContent test fixtures bound-arrows.json 1`] = `
|
|
|
149
149
|
"kind": "arc",
|
|
150
150
|
"labelColor": "black",
|
|
151
151
|
"labelPosition": 0.5,
|
|
152
|
+
"richText": {
|
|
153
|
+
"content": [
|
|
154
|
+
{
|
|
155
|
+
"type": "paragraph",
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
"type": "doc",
|
|
159
|
+
},
|
|
152
160
|
"scale": 1,
|
|
153
161
|
"size": "m",
|
|
154
162
|
"start": {
|
|
155
163
|
"x": 0,
|
|
156
164
|
"y": 0,
|
|
157
165
|
},
|
|
158
|
-
"text": "",
|
|
159
166
|
},
|
|
160
167
|
"rotation": 0,
|
|
161
168
|
"type": "arrow",
|
|
@@ -315,13 +322,20 @@ exports[`putExcalidrawContent test fixtures bound-elbow-arrows.json 1`] = `
|
|
|
315
322
|
"kind": "elbow",
|
|
316
323
|
"labelColor": "black",
|
|
317
324
|
"labelPosition": 0.5,
|
|
325
|
+
"richText": {
|
|
326
|
+
"content": [
|
|
327
|
+
{
|
|
328
|
+
"type": "paragraph",
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
"type": "doc",
|
|
332
|
+
},
|
|
318
333
|
"scale": 1,
|
|
319
334
|
"size": "m",
|
|
320
335
|
"start": {
|
|
321
336
|
"x": 0,
|
|
322
337
|
"y": 0,
|
|
323
338
|
},
|
|
324
|
-
"text": "",
|
|
325
339
|
},
|
|
326
340
|
"rotation": 0,
|
|
327
341
|
"type": "arrow",
|