@tldraw/editor 3.14.0-canary.c76a772c4700 → 3.14.0-canary.c81eaa71a51b
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 +122 -16
- package/dist-cjs/index.js +4 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +80 -24
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +3 -1
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +3 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +0 -10
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +10 -6
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +3 -3
- package/dist-cjs/lib/editor/tools/StateNode.js +3 -3
- package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
- package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
- package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
- package/dist-cjs/lib/hooks/useCanvasEvents.js +1 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +6 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
- package/dist-cjs/lib/utils/reparenting.js +232 -0
- package/dist-cjs/lib/utils/reparenting.js.map +7 -0
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +122 -16
- package/dist-esm/index.mjs +4 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +80 -24
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +3 -1
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +3 -2
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +0 -10
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +10 -6
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +3 -3
- package/dist-esm/lib/editor/tools/StateNode.mjs +3 -3
- package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +1 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +6 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/lib/utils/reparenting.mjs +216 -0
- package/dist-esm/lib/utils/reparenting.mjs.map +7 -0
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +27 -12
- package/package.json +7 -7
- package/src/index.ts +6 -0
- package/src/lib/editor/Editor.ts +99 -34
- package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +3 -1
- package/src/lib/editor/managers/TextManager/TextManager.ts +4 -2
- package/src/lib/editor/shapes/ShapeUtil.ts +47 -15
- package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +22 -17
- package/src/lib/editor/tools/StateNode.ts +3 -3
- package/src/lib/editor/types/emit-types.ts +4 -0
- package/src/lib/editor/types/external-content.ts +11 -2
- package/src/lib/hooks/useCanvasEvents.ts +0 -1
- package/src/lib/primitives/geometry/Geometry2d.ts +7 -2
- package/src/lib/utils/reparenting.ts +383 -0
- package/src/version.ts +3 -3
package/src/lib/editor/Editor.ts
CHANGED
|
@@ -2122,6 +2122,20 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
2122
2122
|
return this.getShapesPageBounds(this.getSelectedShapeIds())
|
|
2123
2123
|
}
|
|
2124
2124
|
|
|
2125
|
+
/**
|
|
2126
|
+
* The bounds of the selection bounding box in the current page space.
|
|
2127
|
+
*
|
|
2128
|
+
* @readonly
|
|
2129
|
+
* @public
|
|
2130
|
+
*/
|
|
2131
|
+
getSelectionScreenBounds(): Box | undefined {
|
|
2132
|
+
const bounds = this.getSelectionPageBounds()
|
|
2133
|
+
if (!bounds) return undefined
|
|
2134
|
+
const { x, y } = this.pageToScreen(bounds.point)
|
|
2135
|
+
const zoom = this.getZoomLevel()
|
|
2136
|
+
return new Box(x, y, bounds.width * zoom, bounds.height * zoom)
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2125
2139
|
/**
|
|
2126
2140
|
* @internal
|
|
2127
2141
|
*/
|
|
@@ -5514,7 +5528,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5514
5528
|
if (!id) return undefined
|
|
5515
5529
|
const freshShape = this.getShape(id)
|
|
5516
5530
|
if (freshShape === undefined || !isShapeId(freshShape.parentId)) return undefined
|
|
5517
|
-
return this.
|
|
5531
|
+
return this.getShape(freshShape.parentId)
|
|
5518
5532
|
}
|
|
5519
5533
|
|
|
5520
5534
|
/**
|
|
@@ -5697,6 +5711,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5697
5711
|
const newPoint = invertedParentTransform.applyToPoint(pagePoint)
|
|
5698
5712
|
const newRotation = pageTransform.rotation() - parentPageRotation
|
|
5699
5713
|
|
|
5714
|
+
if (shape.id === parentId) {
|
|
5715
|
+
throw Error('Attempted to reparent a shape to itself!')
|
|
5716
|
+
}
|
|
5717
|
+
|
|
5700
5718
|
changes.push({
|
|
5701
5719
|
id: shape.id,
|
|
5702
5720
|
type: shape.type,
|
|
@@ -5800,6 +5818,11 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5800
5818
|
return shapeIds
|
|
5801
5819
|
}
|
|
5802
5820
|
|
|
5821
|
+
/** @deprecated Use {@link Editor.getDraggingOverShape} instead */
|
|
5822
|
+
getDroppingOverShape(point: Vec, droppingShapes: TLShape[]): TLShape | undefined {
|
|
5823
|
+
return this.getDraggingOverShape(point, droppingShapes)
|
|
5824
|
+
}
|
|
5825
|
+
|
|
5803
5826
|
/**
|
|
5804
5827
|
* Get the shape that some shapes should be dropped on at a given point.
|
|
5805
5828
|
*
|
|
@@ -5810,35 +5833,33 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5810
5833
|
*
|
|
5811
5834
|
* @public
|
|
5812
5835
|
*/
|
|
5813
|
-
|
|
5814
|
-
//
|
|
5815
|
-
const
|
|
5816
|
-
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
if (
|
|
5820
|
-
// ignore hidden shapes
|
|
5821
|
-
this.isShapeHidden(shape) ||
|
|
5822
|
-
// don't allow dropping on selected shapes
|
|
5823
|
-
this.getSelectedShapeIds().includes(shape.id) ||
|
|
5824
|
-
// only allow shapes that can receive children
|
|
5825
|
-
!this.getShapeUtil(shape).canDropShapes(shape, droppingShapes) ||
|
|
5826
|
-
// don't allow dropping a shape on itself or one of it's children
|
|
5827
|
-
droppingShapes.find((s) => s.id === shape.id || this.hasAncestor(shape, s.id))
|
|
5828
|
-
) {
|
|
5829
|
-
continue
|
|
5830
|
-
}
|
|
5836
|
+
getDraggingOverShape(point: Vec, droppingShapes: TLShape[]): TLShape | undefined {
|
|
5837
|
+
// get fresh moving shapes
|
|
5838
|
+
const draggingShapes = compact(droppingShapes.map((s) => this.getShape(s))).filter(
|
|
5839
|
+
(s) => !s.isLocked && !this.isShapeHidden(s)
|
|
5840
|
+
)
|
|
5831
5841
|
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5842
|
+
const maybeDraggingOverShapes = this.getShapesAtPoint(point, {
|
|
5843
|
+
hitInside: true,
|
|
5844
|
+
margin: 0,
|
|
5845
|
+
}).filter(
|
|
5846
|
+
(s) =>
|
|
5847
|
+
!droppingShapes.includes(s) &&
|
|
5848
|
+
!s.isLocked &&
|
|
5849
|
+
!this.isShapeHidden(s) &&
|
|
5850
|
+
!draggingShapes.includes(s)
|
|
5851
|
+
)
|
|
5835
5852
|
|
|
5853
|
+
for (const maybeDraggingOverShape of maybeDraggingOverShapes) {
|
|
5854
|
+
const shapeUtil = this.getShapeUtil(maybeDraggingOverShape)
|
|
5855
|
+
// Any shape that can handle any dragging interactions is a valid target
|
|
5836
5856
|
if (
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
5857
|
+
shapeUtil.onDragShapesOver ||
|
|
5858
|
+
shapeUtil.onDragShapesIn ||
|
|
5859
|
+
shapeUtil.onDragShapesOut ||
|
|
5860
|
+
shapeUtil.onDropShapesOver
|
|
5840
5861
|
) {
|
|
5841
|
-
return
|
|
5862
|
+
return maybeDraggingOverShape
|
|
5842
5863
|
}
|
|
5843
5864
|
}
|
|
5844
5865
|
}
|
|
@@ -6197,11 +6218,12 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6197
6218
|
*/
|
|
6198
6219
|
duplicateShapes(shapes: TLShapeId[] | TLShape[], offset?: VecLike): this {
|
|
6199
6220
|
this.run(() => {
|
|
6200
|
-
const
|
|
6221
|
+
const _ids =
|
|
6201
6222
|
typeof shapes[0] === 'string'
|
|
6202
6223
|
? (shapes as TLShapeId[])
|
|
6203
6224
|
: (shapes as TLShape[]).map((s) => s.id)
|
|
6204
6225
|
|
|
6226
|
+
const ids = this._shouldIgnoreShapeLock ? _ids : this._getUnlockedShapeIds(_ids)
|
|
6205
6227
|
if (ids.length <= 0) return this
|
|
6206
6228
|
|
|
6207
6229
|
const initialIds = new Set(ids)
|
|
@@ -6281,10 +6303,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6281
6303
|
})
|
|
6282
6304
|
const shapesToCreate = shapesToCreateWithOriginals.map(({ shape }) => shape)
|
|
6283
6305
|
|
|
6284
|
-
|
|
6285
|
-
shapesToCreate.length + this.getCurrentPageShapeIds().size > this.options.maxShapesPerPage
|
|
6286
|
-
|
|
6287
|
-
if (maxShapesReached) {
|
|
6306
|
+
if (!this.canCreateShapes(shapesToCreate)) {
|
|
6288
6307
|
alertMaxShapes(this)
|
|
6289
6308
|
return
|
|
6290
6309
|
}
|
|
@@ -7713,6 +7732,32 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7713
7732
|
return {}
|
|
7714
7733
|
}
|
|
7715
7734
|
|
|
7735
|
+
/**
|
|
7736
|
+
* Get whether the provided shape can be created.
|
|
7737
|
+
*
|
|
7738
|
+
* @param shape - The shape or shape IDs to check.
|
|
7739
|
+
*
|
|
7740
|
+
* @public
|
|
7741
|
+
*/
|
|
7742
|
+
canCreateShape<T extends TLUnknownShape>(
|
|
7743
|
+
shape: OptionalKeys<TLShapePartial<T>, 'id'> | T['id']
|
|
7744
|
+
): boolean {
|
|
7745
|
+
return this.canCreateShapes([shape])
|
|
7746
|
+
}
|
|
7747
|
+
|
|
7748
|
+
/**
|
|
7749
|
+
* Get whether the provided shapes can be created.
|
|
7750
|
+
*
|
|
7751
|
+
* @param shapes - The shapes or shape IDs to create.
|
|
7752
|
+
*
|
|
7753
|
+
* @public
|
|
7754
|
+
*/
|
|
7755
|
+
canCreateShapes<T extends TLUnknownShape>(
|
|
7756
|
+
shapes: (T['id'] | OptionalKeys<TLShapePartial<T>, 'id'>)[]
|
|
7757
|
+
): boolean {
|
|
7758
|
+
return shapes.length + this.getCurrentPageShapeIds().size <= this.options.maxShapesPerPage
|
|
7759
|
+
}
|
|
7760
|
+
|
|
7716
7761
|
/**
|
|
7717
7762
|
* Create a single shape.
|
|
7718
7763
|
*
|
|
@@ -7759,6 +7804,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7759
7804
|
if (maxShapesReached) {
|
|
7760
7805
|
// can't create more shapes than fit on the page
|
|
7761
7806
|
alertMaxShapes(this)
|
|
7807
|
+
// todo: throw an error here? Otherwise we'll need to check every time whether the shapes were actually created
|
|
7762
7808
|
return this
|
|
7763
7809
|
}
|
|
7764
7810
|
|
|
@@ -7791,9 +7837,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7791
7837
|
|
|
7792
7838
|
for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
|
|
7793
7839
|
const parent = currentPageShapesSorted[i]
|
|
7840
|
+
const util = this.getShapeUtil(parent)
|
|
7794
7841
|
if (
|
|
7842
|
+
util.canReceiveNewChildrenOfType(parent, partial.type) &&
|
|
7795
7843
|
!this.isShapeHidden(parent) &&
|
|
7796
|
-
this.getShapeUtil(parent).canReceiveNewChildrenOfType(parent, partial.type) &&
|
|
7797
7844
|
this.isPointInShape(
|
|
7798
7845
|
parent,
|
|
7799
7846
|
// If no parent is provided, then we can treat the
|
|
@@ -7922,6 +7969,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7922
7969
|
}
|
|
7923
7970
|
})
|
|
7924
7971
|
|
|
7972
|
+
this.emit('created-shapes', shapeRecordsToCreate)
|
|
7973
|
+
this.emit('edit')
|
|
7925
7974
|
this.store.put(shapeRecordsToCreate)
|
|
7926
7975
|
})
|
|
7927
7976
|
|
|
@@ -8316,6 +8365,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8316
8365
|
updates.push(updated)
|
|
8317
8366
|
}
|
|
8318
8367
|
|
|
8368
|
+
this.emit('edited-shapes', updates)
|
|
8369
|
+
this.emit('edit')
|
|
8319
8370
|
this.store.put(updates)
|
|
8320
8371
|
})
|
|
8321
8372
|
}
|
|
@@ -8365,6 +8416,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8365
8416
|
})
|
|
8366
8417
|
}
|
|
8367
8418
|
|
|
8419
|
+
this.emit('deleted-shapes', [...allShapeIdsToDelete])
|
|
8420
|
+
this.emit('edit')
|
|
8368
8421
|
return this.run(() => this.store.remove([...allShapeIdsToDelete]))
|
|
8369
8422
|
}
|
|
8370
8423
|
|
|
@@ -8813,6 +8866,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8813
8866
|
} = {
|
|
8814
8867
|
text: null,
|
|
8815
8868
|
files: null,
|
|
8869
|
+
'file-replace': null,
|
|
8816
8870
|
embed: null,
|
|
8817
8871
|
'svg-text': null,
|
|
8818
8872
|
url: null,
|
|
@@ -8862,6 +8916,15 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8862
8916
|
return this.externalContentHandlers[info.type]?.(info as any)
|
|
8863
8917
|
}
|
|
8864
8918
|
|
|
8919
|
+
/**
|
|
8920
|
+
* Handle replacing external content.
|
|
8921
|
+
*
|
|
8922
|
+
* @param info - Info about the external content.
|
|
8923
|
+
*/
|
|
8924
|
+
async replaceExternalContent<E>(info: TLExternalContent<E>): Promise<void> {
|
|
8925
|
+
return this.externalContentHandlers[info.type]?.(info as any)
|
|
8926
|
+
}
|
|
8927
|
+
|
|
8865
8928
|
/**
|
|
8866
8929
|
* Get content that can be exported for the given shape ids.
|
|
8867
8930
|
*
|
|
@@ -9481,6 +9544,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9481
9544
|
previousPagePoint,
|
|
9482
9545
|
currentScreenPoint,
|
|
9483
9546
|
currentPagePoint,
|
|
9547
|
+
originScreenPoint,
|
|
9548
|
+
originPagePoint,
|
|
9484
9549
|
} = this.inputs
|
|
9485
9550
|
|
|
9486
9551
|
const { screenBounds } = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID)!
|
|
@@ -9509,8 +9574,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9509
9574
|
// Reset velocity on pointer down, or when a pinch starts or ends
|
|
9510
9575
|
if (info.name === 'pointer_down' || this.inputs.isPinching) {
|
|
9511
9576
|
pointerVelocity.set(0, 0)
|
|
9512
|
-
|
|
9513
|
-
|
|
9577
|
+
originScreenPoint.setTo(currentScreenPoint)
|
|
9578
|
+
originPagePoint.setTo(currentPagePoint)
|
|
9514
9579
|
}
|
|
9515
9580
|
|
|
9516
9581
|
// todo: We only have to do this if there are multiple users in the document
|
|
@@ -241,7 +241,9 @@ export class HistoryManager<R extends UnknownRecord> {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
bailToMark(id: string) {
|
|
244
|
-
|
|
244
|
+
if (id) {
|
|
245
|
+
this._undo({ pushToRedoStack: false, toMark: id })
|
|
246
|
+
}
|
|
245
247
|
|
|
246
248
|
return this
|
|
247
249
|
}
|
|
@@ -26,6 +26,7 @@ export interface TLMeasureTextOpts {
|
|
|
26
26
|
fontWeight: string
|
|
27
27
|
fontFamily: string
|
|
28
28
|
fontSize: number
|
|
29
|
+
/** This must be a number, e.g. 1.35, not a pixel value. */
|
|
29
30
|
lineHeight: number
|
|
30
31
|
/**
|
|
31
32
|
* When maxWidth is a number, the text will be wrapped to that maxWidth. When maxWidth
|
|
@@ -75,6 +76,7 @@ export class TextManager {
|
|
|
75
76
|
// we need to save the default styles so that we can restore them when we're done
|
|
76
77
|
// these must be the css names, not the js names for the styles
|
|
77
78
|
this.defaultStyles = {
|
|
79
|
+
'overflow-wrap': 'break-word',
|
|
78
80
|
'word-break': 'auto',
|
|
79
81
|
width: null,
|
|
80
82
|
height: null,
|
|
@@ -123,7 +125,7 @@ export class TextManager {
|
|
|
123
125
|
elm.style.setProperty('font-style', opts.fontStyle)
|
|
124
126
|
elm.style.setProperty('font-weight', opts.fontWeight)
|
|
125
127
|
elm.style.setProperty('font-size', opts.fontSize + 'px')
|
|
126
|
-
elm.style.setProperty('line-height', opts.lineHeight
|
|
128
|
+
elm.style.setProperty('line-height', opts.lineHeight.toString())
|
|
127
129
|
elm.style.setProperty('padding', opts.padding)
|
|
128
130
|
|
|
129
131
|
if (opts.maxWidth) {
|
|
@@ -287,7 +289,7 @@ export class TextManager {
|
|
|
287
289
|
elm.style.setProperty('font-style', opts.fontStyle)
|
|
288
290
|
elm.style.setProperty('font-weight', opts.fontWeight)
|
|
289
291
|
elm.style.setProperty('font-size', opts.fontSize + 'px')
|
|
290
|
-
elm.style.setProperty('line-height', opts.lineHeight
|
|
292
|
+
elm.style.setProperty('line-height', opts.lineHeight.toString())
|
|
291
293
|
|
|
292
294
|
const elementWidth = Math.ceil(opts.width - opts.padding * 2)
|
|
293
295
|
elm.style.setProperty('width', `${elementWidth}px`)
|
|
@@ -4,12 +4,15 @@ import { LegacyMigrations, MigrationSequence } from '@tldraw/store'
|
|
|
4
4
|
import {
|
|
5
5
|
RecordProps,
|
|
6
6
|
TLHandle,
|
|
7
|
+
TLParentId,
|
|
7
8
|
TLPropsMigrations,
|
|
8
9
|
TLShape,
|
|
9
10
|
TLShapeCrop,
|
|
11
|
+
TLShapeId,
|
|
10
12
|
TLShapePartial,
|
|
11
13
|
TLUnknownShape,
|
|
12
14
|
} from '@tldraw/tlschema'
|
|
15
|
+
import { IndexKey } from '@tldraw/utils'
|
|
13
16
|
import { ReactElement } from 'react'
|
|
14
17
|
import { Box, SelectionHandle } from '../../primitives/Box'
|
|
15
18
|
import { Vec } from '../../primitives/Vec'
|
|
@@ -387,17 +390,6 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
387
390
|
return false
|
|
388
391
|
}
|
|
389
392
|
|
|
390
|
-
/**
|
|
391
|
-
* Get whether the shape can receive children of a given type.
|
|
392
|
-
*
|
|
393
|
-
* @param shape - The shape type.
|
|
394
|
-
* @param shapes - The shapes that are being dropped.
|
|
395
|
-
* @public
|
|
396
|
-
*/
|
|
397
|
-
canDropShapes(_shape: Shape, _shapes: TLShape[]) {
|
|
398
|
-
return false
|
|
399
|
-
}
|
|
400
|
-
|
|
401
393
|
/**
|
|
402
394
|
* Get the shape as an SVG object.
|
|
403
395
|
*
|
|
@@ -517,7 +509,16 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
517
509
|
): Omit<TLShapePartial<Shape>, 'id' | 'type'> | undefined | void
|
|
518
510
|
|
|
519
511
|
/**
|
|
520
|
-
* A callback called when some other shapes are dragged
|
|
512
|
+
* A callback called when some other shapes are dragged into this one. This fires when the shapes are dragged over the shape for the first time.
|
|
513
|
+
*
|
|
514
|
+
* @param shape - The shape.
|
|
515
|
+
* @param shapes - The shapes that are being dragged in.
|
|
516
|
+
* @public
|
|
517
|
+
*/
|
|
518
|
+
onDragShapesIn?(shape: Shape, shapes: TLShape[], info: TLDragShapesInInfo): void
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* A callback called when some other shapes are dragged over this one. This fires when the shapes are dragged over the shape for the first time (after the onDragShapesIn callback), and again on every update while the shapes are being dragged.
|
|
521
522
|
*
|
|
522
523
|
* @example
|
|
523
524
|
*
|
|
@@ -531,7 +532,7 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
531
532
|
* @param shapes - The shapes that are being dragged over this one.
|
|
532
533
|
* @public
|
|
533
534
|
*/
|
|
534
|
-
onDragShapesOver?(shape: Shape, shapes: TLShape[]): void
|
|
535
|
+
onDragShapesOver?(shape: Shape, shapes: TLShape[], info: TLDragShapesOverInfo): void
|
|
535
536
|
|
|
536
537
|
/**
|
|
537
538
|
* A callback called when some other shapes are dragged out of this one.
|
|
@@ -540,7 +541,7 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
540
541
|
* @param shapes - The shapes that are being dragged out.
|
|
541
542
|
* @public
|
|
542
543
|
*/
|
|
543
|
-
onDragShapesOut?(shape: Shape, shapes: TLShape[]): void
|
|
544
|
+
onDragShapesOut?(shape: Shape, shapes: TLShape[], info: TLDragShapesOutInfo): void
|
|
544
545
|
|
|
545
546
|
/**
|
|
546
547
|
* A callback called when some other shapes are dropped over this one.
|
|
@@ -549,7 +550,7 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
549
550
|
* @param shapes - The shapes that are being dropped over this one.
|
|
550
551
|
* @public
|
|
551
552
|
*/
|
|
552
|
-
onDropShapesOver?(shape: Shape, shapes: TLShape[]): void
|
|
553
|
+
onDropShapesOver?(shape: Shape, shapes: TLShape[], info: TLDropShapesOverInfo): void
|
|
553
554
|
|
|
554
555
|
/**
|
|
555
556
|
* A callback called when a shape starts being resized.
|
|
@@ -745,6 +746,37 @@ export interface TLCropInfo<T extends TLShape> {
|
|
|
745
746
|
crop: TLShapeCrop
|
|
746
747
|
uncroppedSize: { w: number; h: number }
|
|
747
748
|
initialShape: T
|
|
749
|
+
aspectRatioLocked?: boolean
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/** @public */
|
|
753
|
+
export interface TLDragShapesInInfo {
|
|
754
|
+
initialDraggingOverShapeId: TLShapeId | null
|
|
755
|
+
prevDraggingOverShapeId: TLShapeId | null
|
|
756
|
+
initialParentIds: Map<TLShapeId, TLParentId>
|
|
757
|
+
initialIndices: Map<TLShapeId, IndexKey>
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/** @public */
|
|
761
|
+
export interface TLDragShapesOverInfo {
|
|
762
|
+
initialDraggingOverShapeId: TLShapeId | null
|
|
763
|
+
initialParentIds: Map<TLShapeId, TLParentId>
|
|
764
|
+
initialIndices: Map<TLShapeId, IndexKey>
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/** @public */
|
|
768
|
+
export interface TLDragShapesOutInfo {
|
|
769
|
+
nextDraggingOverShapeId: TLShapeId | null
|
|
770
|
+
initialDraggingOverShapeId: TLShapeId | null
|
|
771
|
+
initialParentIds: Map<TLShapeId, TLParentId>
|
|
772
|
+
initialIndices: Map<TLShapeId, IndexKey>
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/** @public */
|
|
776
|
+
export interface TLDropShapesOverInfo {
|
|
777
|
+
initialDraggingOverShapeId: TLShapeId | null
|
|
778
|
+
initialParentIds: Map<TLShapeId, TLParentId>
|
|
779
|
+
initialIndices: Map<TLShapeId, IndexKey>
|
|
748
780
|
}
|
|
749
781
|
|
|
750
782
|
/**
|
|
@@ -11,29 +11,33 @@ export class Pointing extends StateNode {
|
|
|
11
11
|
static override id = 'pointing'
|
|
12
12
|
|
|
13
13
|
override onPointerMove(info: TLPointerEventInfo) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const { editor } = this
|
|
15
|
+
if (editor.inputs.isDragging) {
|
|
16
|
+
const { originPagePoint } = editor.inputs
|
|
16
17
|
|
|
17
18
|
const shapeType = (this.parent as BaseBoxShapeTool)!.shapeType
|
|
18
19
|
|
|
19
20
|
const id = createShapeId()
|
|
20
21
|
|
|
21
|
-
const creatingMarkId =
|
|
22
|
-
const newPoint = maybeSnapToGrid(originPagePoint,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
const creatingMarkId = editor.markHistoryStoppingPoint(`creating_box:${id}`)
|
|
23
|
+
const newPoint = maybeSnapToGrid(originPagePoint, editor)
|
|
24
|
+
|
|
25
|
+
// Allow this to trigger the max shapes reached alert
|
|
26
|
+
this.editor.createShapes<TLBaseBoxShape>([
|
|
27
|
+
{
|
|
28
|
+
id,
|
|
29
|
+
type: shapeType,
|
|
30
|
+
x: newPoint.x,
|
|
31
|
+
y: newPoint.y,
|
|
32
|
+
props: {
|
|
33
|
+
w: 1,
|
|
34
|
+
h: 1,
|
|
34
35
|
},
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
},
|
|
37
|
+
])
|
|
38
|
+
const shape = editor.getShape(id)
|
|
39
|
+
if (!shape) this.cancel()
|
|
40
|
+
editor.select(id)
|
|
37
41
|
|
|
38
42
|
const parent = this.parent as BaseBoxShapeTool
|
|
39
43
|
this.editor.setCurrentTool(
|
|
@@ -79,6 +83,7 @@ export class Pointing extends StateNode {
|
|
|
79
83
|
|
|
80
84
|
this.editor.markHistoryStoppingPoint(`creating_box:${id}`)
|
|
81
85
|
|
|
86
|
+
// Allow this to trigger the max shapes reached alert
|
|
82
87
|
// todo: add scale here when dynamic size is enabled (is this still needed?)
|
|
83
88
|
this.editor.createShapes<TLBaseBoxShape>([
|
|
84
89
|
{
|
|
@@ -206,15 +206,15 @@ export abstract class StateNode implements Partial<TLEventHandlers> {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
// todo: move this logic into transition
|
|
209
|
-
exit(info: any,
|
|
209
|
+
exit(info: any, to: string) {
|
|
210
210
|
if (debugFlags.measurePerformance.get() && this.performanceTracker.isStarted()) {
|
|
211
211
|
this.performanceTracker.stop()
|
|
212
212
|
}
|
|
213
213
|
this._isActive.set(false)
|
|
214
|
-
this.onExit?.(info,
|
|
214
|
+
this.onExit?.(info, to)
|
|
215
215
|
|
|
216
216
|
if (!this.getIsActive()) {
|
|
217
|
-
this.getCurrent()?.exit(info,
|
|
217
|
+
this.getCurrent()?.exit(info, to)
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -18,6 +18,10 @@ export interface TLEventMap {
|
|
|
18
18
|
frame: [number]
|
|
19
19
|
'select-all-text': [{ shapeId: TLShapeId }]
|
|
20
20
|
'place-caret': [{ shapeId: TLShapeId; point: { x: number; y: number } }]
|
|
21
|
+
'created-shapes': [TLRecord[]]
|
|
22
|
+
'edited-shapes': [TLRecord[]]
|
|
23
|
+
'deleted-shapes': [TLShapeId[]]
|
|
24
|
+
edit: []
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
/** @public */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TLAssetId } from '@tldraw/tlschema'
|
|
1
|
+
import { TLAssetId, TLShapeId } from '@tldraw/tlschema'
|
|
2
2
|
import { VecLike } from '../../primitives/Vec'
|
|
3
3
|
import { TLContent } from './clipboard-types'
|
|
4
4
|
|
|
@@ -52,7 +52,15 @@ export interface TLTextExternalContent extends TLBaseExternalContent {
|
|
|
52
52
|
export interface TLFilesExternalContent extends TLBaseExternalContent {
|
|
53
53
|
type: 'files'
|
|
54
54
|
files: File[]
|
|
55
|
-
ignoreParent
|
|
55
|
+
ignoreParent?: boolean
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** @public */
|
|
59
|
+
export interface TLFileReplaceExternalContent extends TLBaseExternalContent {
|
|
60
|
+
type: 'file-replace'
|
|
61
|
+
file: File
|
|
62
|
+
shapeId: TLShapeId
|
|
63
|
+
isImage: boolean
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
/** @public */
|
|
@@ -90,6 +98,7 @@ export interface TLExcalidrawExternalContent extends TLBaseExternalContent {
|
|
|
90
98
|
export type TLExternalContent<EmbedDefinition> =
|
|
91
99
|
| TLTextExternalContent
|
|
92
100
|
| TLFilesExternalContent
|
|
101
|
+
| TLFileReplaceExternalContent
|
|
93
102
|
| TLUrlExternalContent
|
|
94
103
|
| TLSvgTextExternalContent
|
|
95
104
|
| TLEmbedExternalContent<EmbedDefinition>
|
|
@@ -44,6 +44,7 @@ export const Geometry2dFilters: {
|
|
|
44
44
|
/** @public */
|
|
45
45
|
export interface TransformedGeometry2dOptions {
|
|
46
46
|
isLabel?: boolean
|
|
47
|
+
isEmptyLabel?: boolean
|
|
47
48
|
isInternal?: boolean
|
|
48
49
|
debugColor?: string
|
|
49
50
|
ignore?: boolean
|
|
@@ -57,20 +58,24 @@ export interface Geometry2dOptions extends TransformedGeometry2dOptions {
|
|
|
57
58
|
|
|
58
59
|
/** @public */
|
|
59
60
|
export abstract class Geometry2d {
|
|
61
|
+
// todo: consider making accessors for these too, so that they can be overridden in subclasses by geometries with more complex logic
|
|
60
62
|
isFilled = false
|
|
61
63
|
isClosed = true
|
|
62
64
|
isLabel = false
|
|
65
|
+
isEmptyLabel = false
|
|
63
66
|
isInternal = false
|
|
64
67
|
debugColor?: string
|
|
65
68
|
ignore?: boolean
|
|
66
69
|
|
|
67
70
|
constructor(opts: Geometry2dOptions) {
|
|
71
|
+
const { isLabel = false, isEmptyLabel = false, isInternal = false } = opts
|
|
68
72
|
this.isFilled = opts.isFilled
|
|
69
73
|
this.isClosed = opts.isClosed
|
|
70
|
-
this.isLabel = opts.isLabel ?? false
|
|
71
|
-
this.isInternal = opts.isInternal ?? false
|
|
72
74
|
this.debugColor = opts.debugColor
|
|
73
75
|
this.ignore = opts.ignore
|
|
76
|
+
this.isLabel = isLabel
|
|
77
|
+
this.isEmptyLabel = isEmptyLabel
|
|
78
|
+
this.isInternal = isInternal
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
isExcludedByFilter(filters?: Geometry2dFilters) {
|