@tldraw/editor 4.6.0-next.e390fde97eab → 4.6.0-next.f17381e03ffe
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 +90 -0
- package/dist-cjs/index.js +3 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/components/LiveCollaborators.js +1 -0
- package/dist-cjs/lib/components/LiveCollaborators.js.map +2 -2
- package/dist-cjs/lib/components/MenuClickCapture.js +93 -47
- package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
- package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js +7 -0
- package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js.map +3 -3
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +5 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js +1 -0
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +64 -5
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/assets/AssetUtil.js +1 -0
- package/dist-cjs/lib/editor/assets/AssetUtil.js.map +1 -1
- package/dist-cjs/lib/editor/bindings/BindingUtil.js +1 -0
- package/dist-cjs/lib/editor/bindings/BindingUtil.js.map +1 -1
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +1 -0
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +1 -0
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js +1 -0
- package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js +2 -0
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +2 -0
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js +12 -0
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js +1 -0
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +1 -0
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +1 -1
- package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js +1 -0
- package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +1 -1
- package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js +2 -1
- package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +1 -0
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +1 -0
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js +1 -0
- package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js +1 -0
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +2 -0
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +1 -1
- package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js +76 -0
- package/dist-cjs/lib/editor/shapes/BaseFrameLikeShapeUtil.js.map +7 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +11 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/tools/StateNode.js +1 -0
- package/dist-cjs/lib/editor/tools/StateNode.js.map +1 -1
- package/dist-cjs/lib/exports/ExportDelay.js +1 -0
- package/dist-cjs/lib/exports/ExportDelay.js.map +1 -1
- package/dist-cjs/lib/exports/StyleEmbedder.js +1 -0
- package/dist-cjs/lib/exports/StyleEmbedder.js.map +1 -1
- package/dist-cjs/lib/exports/getSvgJsx.js +2 -1
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +25 -4
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/options.js +2 -0
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/primitives/Vec.js +3 -0
- package/dist-cjs/lib/primitives/Vec.js.map +1 -1
- package/dist-cjs/lib/primitives/geometry/Circle2d.js +1 -0
- package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +1 -1
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +1 -0
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +1 -1
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +2 -0
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +1 -1
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js +1 -0
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js.map +1 -1
- package/dist-cjs/lib/utils/EditorAtom.js +2 -0
- package/dist-cjs/lib/utils/EditorAtom.js.map +1 -1
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +2 -0
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +1 -1
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +90 -0
- package/dist-esm/index.mjs +3 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/components/LiveCollaborators.mjs +1 -0
- package/dist-esm/lib/components/LiveCollaborators.mjs.map +2 -2
- package/dist-esm/lib/components/MenuClickCapture.mjs +94 -48
- package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs +7 -0
- package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs.map +3 -3
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +5 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs +1 -0
- package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +65 -6
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/assets/AssetUtil.mjs +1 -0
- package/dist-esm/lib/editor/assets/AssetUtil.mjs.map +1 -1
- package/dist-esm/lib/editor/bindings/BindingUtil.mjs +1 -0
- package/dist-esm/lib/editor/bindings/BindingUtil.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +1 -0
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +1 -0
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs +1 -0
- package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs +2 -0
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +2 -0
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs +12 -0
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs +1 -0
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +1 -0
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs +1 -0
- package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs +2 -1
- package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +1 -0
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +1 -0
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs +1 -0
- package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs +1 -0
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +2 -0
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +1 -1
- package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs +56 -0
- package/dist-esm/lib/editor/shapes/BaseFrameLikeShapeUtil.mjs.map +7 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +11 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/StateNode.mjs +1 -0
- package/dist-esm/lib/editor/tools/StateNode.mjs.map +1 -1
- package/dist-esm/lib/exports/ExportDelay.mjs +1 -0
- package/dist-esm/lib/exports/ExportDelay.mjs.map +1 -1
- package/dist-esm/lib/exports/StyleEmbedder.mjs +1 -0
- package/dist-esm/lib/exports/StyleEmbedder.mjs.map +1 -1
- package/dist-esm/lib/exports/getSvgJsx.mjs +2 -1
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +25 -4
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +2 -0
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/primitives/Vec.mjs +3 -0
- package/dist-esm/lib/primitives/Vec.mjs.map +1 -1
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs +1 -0
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +1 -1
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +1 -0
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +1 -1
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +2 -0
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +1 -1
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs +1 -0
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs.map +1 -1
- package/dist-esm/lib/utils/EditorAtom.mjs +2 -0
- package/dist-esm/lib/utils/EditorAtom.mjs.map +1 -1
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +2 -0
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +1 -1
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +0 -4
- package/package.json +7 -7
- package/src/index.ts +1 -0
- package/src/lib/components/LiveCollaborators.tsx +8 -2
- package/src/lib/components/MenuClickCapture.tsx +124 -64
- package/src/lib/components/default-components/CanvasShapeIndicators.tsx +11 -0
- package/src/lib/components/default-components/DefaultCanvas.tsx +6 -2
- package/src/lib/components/default-components/DefaultShapeIndicator.tsx +2 -2
- package/src/lib/components/default-components/DefaultShapeIndicators.tsx +2 -0
- package/src/lib/editor/Editor.ts +87 -14
- package/src/lib/editor/managers/InputsManager/InputsManager.ts +12 -0
- package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +13 -2
- package/src/lib/editor/managers/SnapManager/SnapManager.ts +1 -1
- package/src/lib/editor/shapes/BaseFrameLikeShapeUtil.tsx +121 -0
- package/src/lib/editor/shapes/ShapeUtil.ts +11 -0
- package/src/lib/exports/getSvgJsx.tsx +2 -1
- package/src/lib/hooks/useCanvasEvents.ts +40 -3
- package/src/lib/options.ts +14 -0
- package/src/version.ts +3 -3
|
@@ -77,8 +77,13 @@ describe('SnapManager', () => {
|
|
|
77
77
|
})),
|
|
78
78
|
getShapePageBounds: vi.fn(),
|
|
79
79
|
isShapeOfType: vi.fn(),
|
|
80
|
+
isShapeFrameLike: vi.fn(() => false),
|
|
80
81
|
} as any
|
|
81
82
|
|
|
83
|
+
editor.getShapeUtil.mockReturnValue({
|
|
84
|
+
canSnap: vi.fn(() => true),
|
|
85
|
+
} as any)
|
|
86
|
+
|
|
82
87
|
snapManager = new SnapManager(editor)
|
|
83
88
|
})
|
|
84
89
|
|
|
@@ -351,7 +356,10 @@ describe('SnapManager', () => {
|
|
|
351
356
|
|
|
352
357
|
editor.getSortedChildIdsForParent.mockReturnValue([frameId])
|
|
353
358
|
editor.getShape.mockReturnValue(frameShape)
|
|
354
|
-
editor.
|
|
359
|
+
editor.getShapeUtil.mockReturnValue({
|
|
360
|
+
canSnap: vi.fn(() => true),
|
|
361
|
+
} as any)
|
|
362
|
+
editor.isShapeFrameLike.mockReturnValue(true)
|
|
355
363
|
editor.getShapePageBounds.mockReturnValue(new Box(10, 10, 50, 50))
|
|
356
364
|
|
|
357
365
|
const result = snapManager.getSnappableShapes()
|
|
@@ -401,7 +409,10 @@ describe('SnapManager', () => {
|
|
|
401
409
|
return undefined
|
|
402
410
|
})
|
|
403
411
|
|
|
404
|
-
editor.
|
|
412
|
+
editor.getShapeUtil.mockReturnValue({
|
|
413
|
+
canSnap: vi.fn(() => true),
|
|
414
|
+
} as any)
|
|
415
|
+
editor.isShapeFrameLike.mockReturnValue(true)
|
|
405
416
|
editor.getShapePageBounds.mockReturnValue(new Box(10, 10, 50, 50))
|
|
406
417
|
|
|
407
418
|
const result = snapManager.getSnappableShapes()
|
|
@@ -72,7 +72,7 @@ export class SnapManager {
|
|
|
72
72
|
const collectSnappableShapesFromParent = (parentId: TLParentId) => {
|
|
73
73
|
if (isShapeId(parentId)) {
|
|
74
74
|
const parent = editor.getShape(parentId)
|
|
75
|
-
if (parent && editor.
|
|
75
|
+
if (parent && editor.isShapeFrameLike(parent)) {
|
|
76
76
|
snappableShapes.add(parentId)
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { TLShape, TLShapeId } from '@tldraw/tlschema'
|
|
2
|
+
import { IndexKey, compact } from '@tldraw/utils'
|
|
3
|
+
import { Vec } from '../../primitives/Vec'
|
|
4
|
+
import { BaseBoxShapeUtil, TLBaseBoxShape } from './BaseBoxShapeUtil'
|
|
5
|
+
import { TLDragShapesInInfo, TLDragShapesOutInfo } from './ShapeUtil'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A base class for frame-like shapes — containers that clip their children,
|
|
9
|
+
* require full-brush selection, block erasure from inside, and support
|
|
10
|
+
* drag-and-drop reparenting.
|
|
11
|
+
*
|
|
12
|
+
* Extending this class is the easiest way to create a custom frame-like shape.
|
|
13
|
+
* It provides sensible defaults for all frame-like behaviors:
|
|
14
|
+
*
|
|
15
|
+
* - `isFrameLike()` returns `true`
|
|
16
|
+
* - `providesBackgroundForChildren()` returns `true`
|
|
17
|
+
* - `canReceiveNewChildrenOfType()` returns `true` unless the container is locked
|
|
18
|
+
* - `getClipPath()` returns the shape geometry's vertices
|
|
19
|
+
* - `onDragShapesIn()` reparents shapes into the frame (with index restoration)
|
|
20
|
+
* - `onDragShapesOut()` reparents shapes back to the page
|
|
21
|
+
*
|
|
22
|
+
* All methods can be overridden for custom behavior.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* class MyContainerUtil extends BaseFrameLikeShapeUtil<MyContainerShape> {
|
|
27
|
+
* static override type = 'my-container' as const
|
|
28
|
+
* static override props = myContainerShapeProps
|
|
29
|
+
*
|
|
30
|
+
* override getDefaultProps() {
|
|
31
|
+
* return { w: 300, h: 200 }
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* override component(shape: MyContainerShape) {
|
|
35
|
+
* return <SVGContainer>...</SVGContainer>
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* override indicator(shape: MyContainerShape) {
|
|
39
|
+
* return <rect width={shape.props.w} height={shape.props.h} />
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
export abstract class BaseFrameLikeShapeUtil<
|
|
47
|
+
Shape extends TLBaseBoxShape,
|
|
48
|
+
> extends BaseBoxShapeUtil<Shape> {
|
|
49
|
+
override isFrameLike(_shape: Shape): boolean {
|
|
50
|
+
return true
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override providesBackgroundForChildren(): boolean {
|
|
54
|
+
return true
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
override canReceiveNewChildrenOfType(shape: Shape, _type: TLShape['type']): boolean {
|
|
58
|
+
return !shape.isLocked
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
override getClipPath(shape: Shape): Vec[] | undefined {
|
|
62
|
+
return this.editor.getShapeGeometry(shape.id).vertices
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override onDragShapesIn(
|
|
66
|
+
shape: Shape,
|
|
67
|
+
draggingShapes: TLShape[],
|
|
68
|
+
{ initialParentIds, initialIndices }: TLDragShapesInInfo
|
|
69
|
+
): void {
|
|
70
|
+
const { editor } = this
|
|
71
|
+
|
|
72
|
+
if (draggingShapes.every((s) => s.parentId === shape.id)) return
|
|
73
|
+
|
|
74
|
+
// Check to see whether any of the shapes can have their old index restored
|
|
75
|
+
let canRestoreOriginalIndices = false
|
|
76
|
+
const previousChildren = draggingShapes.filter(
|
|
77
|
+
(s) => shape.id === (initialParentIds.get(s.id) as TLShapeId)
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
if (previousChildren.length > 0) {
|
|
81
|
+
const currentChildren = compact(
|
|
82
|
+
editor.getSortedChildIdsForParent(shape).map((id) => editor.getShape(id))
|
|
83
|
+
)
|
|
84
|
+
if (previousChildren.every((s) => !currentChildren.find((c) => c.index === s.index))) {
|
|
85
|
+
canRestoreOriginalIndices = true
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// If any of the children are the ancestor of the frame, quit here
|
|
90
|
+
if (draggingShapes.some((s) => editor.hasAncestor(shape, s.id))) return
|
|
91
|
+
|
|
92
|
+
editor.reparentShapes(draggingShapes, shape.id)
|
|
93
|
+
|
|
94
|
+
if (canRestoreOriginalIndices) {
|
|
95
|
+
for (const s of previousChildren) {
|
|
96
|
+
editor.updateShape({
|
|
97
|
+
id: s.id,
|
|
98
|
+
type: s.type,
|
|
99
|
+
index: initialIndices.get(s.id) as IndexKey,
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
override onDragShapesOut(
|
|
106
|
+
shape: Shape,
|
|
107
|
+
draggingShapes: TLShape[],
|
|
108
|
+
info: TLDragShapesOutInfo
|
|
109
|
+
): void {
|
|
110
|
+
const { editor } = this
|
|
111
|
+
// When a user drags shapes out and we're not dragging into a new shape,
|
|
112
|
+
// reparent the dragging shapes onto the current page instead
|
|
113
|
+
if (!info.nextDraggingOverShapeId) {
|
|
114
|
+
// Locked shapes are already filtered out upstream by DragAndDropManager.
|
|
115
|
+
editor.reparentShapes(
|
|
116
|
+
draggingShapes.filter((s) => s.parentId === shape.id),
|
|
117
|
+
editor.getCurrentPageId()
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -492,6 +492,17 @@ export abstract class ShapeUtil<Shape extends TLShape = TLShape> {
|
|
|
492
492
|
return false
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
+
/**
|
|
496
|
+
* Whether the shape behaves like a frame — a container that has child shapes,
|
|
497
|
+
* requires full-brush selection, blocks erasure from inside, etc.
|
|
498
|
+
*
|
|
499
|
+
* @param shape - The shape.
|
|
500
|
+
* @public
|
|
501
|
+
*/
|
|
502
|
+
isFrameLike(_shape: Shape): boolean {
|
|
503
|
+
return false
|
|
504
|
+
}
|
|
505
|
+
|
|
495
506
|
/**
|
|
496
507
|
* By default, the bounds of an image export are the bounds of all the shapes it contains, plus
|
|
497
508
|
* some padding. If an export includes a shape where `isExportBoundsContainer` is true, then the
|
|
@@ -60,8 +60,9 @@ export function getSvgJsx(editor: Editor, ids: TLShapeId[], opts: TLImageExportO
|
|
|
60
60
|
.filter(({ id }) => shapeIdsToInclude.has(id))
|
|
61
61
|
|
|
62
62
|
// --- Common bounding box of all shapes
|
|
63
|
+
const singleFrameShape = ids.length === 1 ? editor.getShape(ids[0]) : null
|
|
63
64
|
const singleFrameShapeId =
|
|
64
|
-
|
|
65
|
+
singleFrameShape && editor.isShapeFrameLike(singleFrameShape) ? ids[0] : null
|
|
65
66
|
|
|
66
67
|
let bbox: null | Box = null
|
|
67
68
|
let paddingWasApplied = false
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useValue } from '@tldraw/state-react'
|
|
2
2
|
import React, { useEffect, useMemo } from 'react'
|
|
3
|
-
import { RIGHT_MOUSE_BUTTON } from '../constants'
|
|
4
3
|
import { tlenv } from '../globals/environment'
|
|
5
4
|
import {
|
|
6
5
|
elementShouldCaptureKeys,
|
|
@@ -21,7 +20,9 @@ export function useCanvasEvents() {
|
|
|
21
20
|
function onPointerDown(e: React.PointerEvent) {
|
|
22
21
|
if (editor.wasEventAlreadyHandled(e)) return
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
// With right-click panning disabled, fire right_click on press and let the
|
|
24
|
+
// native contextmenu through so the menu opens at the pointer-down location.
|
|
25
|
+
if (e.button === 2 && !editor.options.rightClickPanning) {
|
|
25
26
|
editor.dispatch({
|
|
26
27
|
type: 'pointer',
|
|
27
28
|
target: 'canvas',
|
|
@@ -31,7 +32,7 @@ export function useCanvasEvents() {
|
|
|
31
32
|
return
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
if (e.button !== 0 && e.button !== 1 && e.button !== 5) return
|
|
35
|
+
if (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return
|
|
35
36
|
|
|
36
37
|
setPointerCapture(e.currentTarget, e)
|
|
37
38
|
|
|
@@ -47,6 +48,11 @@ export function useCanvasEvents() {
|
|
|
47
48
|
if (editor.wasEventAlreadyHandled(e)) return
|
|
48
49
|
if (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return
|
|
49
50
|
|
|
51
|
+
const rightClickPanning = editor.options.rightClickPanning
|
|
52
|
+
// Check before dispatch (which resets isPanning)
|
|
53
|
+
const wasRightClickPanning =
|
|
54
|
+
rightClickPanning && e.button === 2 && editor.inputs.getIsPanning()
|
|
55
|
+
|
|
50
56
|
releasePointerCapture(e.currentTarget, e)
|
|
51
57
|
|
|
52
58
|
editor.dispatch({
|
|
@@ -55,6 +61,21 @@ export function useCanvasEvents() {
|
|
|
55
61
|
name: 'pointer_up',
|
|
56
62
|
...getPointerInfo(editor, e),
|
|
57
63
|
})
|
|
64
|
+
|
|
65
|
+
// Static right-click: fire contextmenu at the pointer-up location
|
|
66
|
+
if (rightClickPanning && e.button === 2 && !wasRightClickPanning) {
|
|
67
|
+
const contextMenuEvent = new PointerEvent('contextmenu', {
|
|
68
|
+
bubbles: true,
|
|
69
|
+
clientX: e.clientX,
|
|
70
|
+
clientY: e.clientY,
|
|
71
|
+
button: 2,
|
|
72
|
+
buttons: 0,
|
|
73
|
+
pointerId: e.pointerId,
|
|
74
|
+
pointerType: e.pointerType,
|
|
75
|
+
isPrimary: e.isPrimary,
|
|
76
|
+
})
|
|
77
|
+
e.currentTarget.dispatchEvent(contextMenuEvent)
|
|
78
|
+
}
|
|
58
79
|
}
|
|
59
80
|
|
|
60
81
|
function onPointerEnter(e: React.PointerEvent) {
|
|
@@ -143,6 +164,21 @@ export function useCanvasEvents() {
|
|
|
143
164
|
e.stopPropagation()
|
|
144
165
|
}
|
|
145
166
|
|
|
167
|
+
function onContextMenu(e: React.MouseEvent) {
|
|
168
|
+
// With right-click panning disabled, let the native contextmenu through so the
|
|
169
|
+
// menu opens on press.
|
|
170
|
+
if (!editor.options.rightClickPanning) return
|
|
171
|
+
// Synthetic events — our own dispatch from onPointerUp, or tests using
|
|
172
|
+
// fireEvent.contextMenu — pass through so Radix can open the menu. The real
|
|
173
|
+
// browser contextmenu is always suppressed: right-click behavior has
|
|
174
|
+
// already been decided by our pointer handling (either we dispatched a
|
|
175
|
+
// synthetic to open the menu at the release position, or we panned and
|
|
176
|
+
// don't want a menu at all).
|
|
177
|
+
if (e.nativeEvent.isTrusted) {
|
|
178
|
+
preventDefault(e)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
146
182
|
return {
|
|
147
183
|
onPointerDown,
|
|
148
184
|
onPointerUp,
|
|
@@ -153,6 +189,7 @@ export function useCanvasEvents() {
|
|
|
153
189
|
onTouchStart,
|
|
154
190
|
onTouchEnd,
|
|
155
191
|
onClick,
|
|
192
|
+
onContextMenu,
|
|
156
193
|
}
|
|
157
194
|
},
|
|
158
195
|
[editor]
|
package/src/lib/options.ts
CHANGED
|
@@ -154,6 +154,12 @@ export interface TldrawOptions {
|
|
|
154
154
|
* When false, the spacebar will not pan the camera.
|
|
155
155
|
*/
|
|
156
156
|
readonly spacebarPanning: boolean
|
|
157
|
+
/**
|
|
158
|
+
* Whether to allow right-click + drag to pan the camera. When true, right-click + drag pans the
|
|
159
|
+
* camera and a static right-click opens the context menu at the release position. When false,
|
|
160
|
+
* right-click opens the context menu on press (no drag-to-pan).
|
|
161
|
+
*/
|
|
162
|
+
readonly rightClickPanning: boolean
|
|
157
163
|
/**
|
|
158
164
|
* The default padding (in pixels) used when zooming to fit content in the viewport.
|
|
159
165
|
* This affects methods like `zoomToFit()`, `zoomToSelection()`, and `zoomToBounds()`.
|
|
@@ -196,6 +202,12 @@ export interface TldrawOptions {
|
|
|
196
202
|
* viewport's page dimensions regardless of overview zoom changes.
|
|
197
203
|
*/
|
|
198
204
|
readonly quickZoomPreservesScreenBounds: boolean
|
|
205
|
+
/**
|
|
206
|
+
* Whether to use 2D canvas rendering for shape indicators. When true (default),
|
|
207
|
+
* shapes that support it will render indicators on a 2D canvas for better
|
|
208
|
+
* performance. When false, all indicators use legacy SVG rendering.
|
|
209
|
+
*/
|
|
210
|
+
readonly useCanvasIndicators: boolean
|
|
199
211
|
/**
|
|
200
212
|
* Called before content is written to the clipboard during a copy or cut operation.
|
|
201
213
|
* Receives the serialized content (shapes, bindings, assets) and can filter or transform
|
|
@@ -326,11 +338,13 @@ export const defaultTldrawOptions = {
|
|
|
326
338
|
debouncedZoom: true,
|
|
327
339
|
debouncedZoomThreshold: 500,
|
|
328
340
|
spacebarPanning: true,
|
|
341
|
+
rightClickPanning: true,
|
|
329
342
|
zoomToFitPadding: 128,
|
|
330
343
|
snapThreshold: 8,
|
|
331
344
|
camera: DEFAULT_CAMERA_OPTIONS,
|
|
332
345
|
text: {},
|
|
333
346
|
deepLinks: undefined,
|
|
347
|
+
useCanvasIndicators: true,
|
|
334
348
|
quickZoomPreservesScreenBounds: true,
|
|
335
349
|
onBeforeCopyToClipboard: undefined,
|
|
336
350
|
onBeforePasteFromClipboard: undefined,
|
package/src/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.6.0-next.
|
|
4
|
+
export const version = '4.6.0-next.f17381e03ffe'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2025-09-18T14:39:22.803Z',
|
|
7
|
-
minor: '2026-04-
|
|
8
|
-
patch: '2026-04-
|
|
7
|
+
minor: '2026-04-25T18:53:46.038Z',
|
|
8
|
+
patch: '2026-04-25T18:53:46.038Z',
|
|
9
9
|
}
|