@tldraw/editor 3.14.0-canary.e989a4107be2 → 3.14.0-canary.ea2c4acfa022

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.
Files changed (66) hide show
  1. package/dist-cjs/index.d.ts +14 -99
  2. package/dist-cjs/index.js +1 -4
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/editor/Editor.js +25 -59
  5. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  6. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +1 -3
  7. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +2 -2
  8. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +2 -3
  9. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  10. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +10 -0
  11. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  12. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +6 -10
  13. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +3 -3
  14. package/dist-cjs/lib/editor/tools/StateNode.js +3 -3
  15. package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
  16. package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
  17. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +2 -6
  18. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  19. package/dist-cjs/lib/primitives/geometry/Group2d.js +6 -11
  20. package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
  21. package/dist-cjs/lib/utils/dom.js +1 -1
  22. package/dist-cjs/lib/utils/dom.js.map +2 -2
  23. package/dist-cjs/version.js +3 -3
  24. package/dist-cjs/version.js.map +1 -1
  25. package/dist-esm/index.d.mts +14 -99
  26. package/dist-esm/index.mjs +1 -4
  27. package/dist-esm/index.mjs.map +2 -2
  28. package/dist-esm/lib/editor/Editor.mjs +25 -59
  29. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  30. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +1 -3
  31. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +2 -2
  32. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +2 -3
  33. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  34. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +10 -0
  35. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  36. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +6 -10
  37. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +3 -3
  38. package/dist-esm/lib/editor/tools/StateNode.mjs +3 -3
  39. package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
  40. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +2 -6
  41. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  42. package/dist-esm/lib/primitives/geometry/Group2d.mjs +6 -11
  43. package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
  44. package/dist-esm/lib/utils/dom.mjs +1 -1
  45. package/dist-esm/lib/utils/dom.mjs.map +2 -2
  46. package/dist-esm/version.mjs +3 -3
  47. package/dist-esm/version.mjs.map +1 -1
  48. package/editor.css +11 -17
  49. package/package.json +7 -7
  50. package/src/index.ts +0 -5
  51. package/src/lib/editor/Editor.ts +36 -77
  52. package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +1 -3
  53. package/src/lib/editor/managers/TextManager/TextManager.ts +2 -4
  54. package/src/lib/editor/shapes/ShapeUtil.ts +15 -47
  55. package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +17 -22
  56. package/src/lib/editor/tools/StateNode.ts +3 -3
  57. package/src/lib/editor/types/emit-types.ts +0 -4
  58. package/src/lib/primitives/geometry/Geometry2d.ts +2 -7
  59. package/src/lib/primitives/geometry/Group2d.ts +5 -11
  60. package/src/lib/utils/dom.ts +1 -1
  61. package/src/version.ts +3 -3
  62. package/dist-cjs/lib/utils/reparenting.js +0 -232
  63. package/dist-cjs/lib/utils/reparenting.js.map +0 -7
  64. package/dist-esm/lib/utils/reparenting.mjs +0 -216
  65. package/dist-esm/lib/utils/reparenting.mjs.map +0 -7
  66. package/src/lib/utils/reparenting.ts +0 -383
@@ -3662,7 +3662,7 @@ export class Editor extends EventEmitter<TLEventMap> {
3662
3662
  * @public
3663
3663
  */
3664
3664
  updateViewportScreenBounds(screenBounds: Box | HTMLElement, center = false): this {
3665
- if (!(screenBounds instanceof Box)) {
3665
+ if (screenBounds instanceof HTMLElement) {
3666
3666
  const rect = screenBounds.getBoundingClientRect()
3667
3667
  screenBounds = new Box(
3668
3668
  rect.left || rect.x,
@@ -5528,7 +5528,7 @@ export class Editor extends EventEmitter<TLEventMap> {
5528
5528
  if (!id) return undefined
5529
5529
  const freshShape = this.getShape(id)
5530
5530
  if (freshShape === undefined || !isShapeId(freshShape.parentId)) return undefined
5531
- return this.getShape(freshShape.parentId)
5531
+ return this.store.get(freshShape.parentId)
5532
5532
  }
5533
5533
 
5534
5534
  /**
@@ -5711,10 +5711,6 @@ export class Editor extends EventEmitter<TLEventMap> {
5711
5711
  const newPoint = invertedParentTransform.applyToPoint(pagePoint)
5712
5712
  const newRotation = pageTransform.rotation() - parentPageRotation
5713
5713
 
5714
- if (shape.id === parentId) {
5715
- throw Error('Attempted to reparent a shape to itself!')
5716
- }
5717
-
5718
5714
  changes.push({
5719
5715
  id: shape.id,
5720
5716
  type: shape.type,
@@ -5818,11 +5814,6 @@ export class Editor extends EventEmitter<TLEventMap> {
5818
5814
  return shapeIds
5819
5815
  }
5820
5816
 
5821
- /** @deprecated Use {@link Editor.getDraggingOverShape} instead */
5822
- getDroppingOverShape(point: Vec, droppingShapes: TLShape[]): TLShape | undefined {
5823
- return this.getDraggingOverShape(point, droppingShapes)
5824
- }
5825
-
5826
5817
  /**
5827
5818
  * Get the shape that some shapes should be dropped on at a given point.
5828
5819
  *
@@ -5833,33 +5824,35 @@ export class Editor extends EventEmitter<TLEventMap> {
5833
5824
  *
5834
5825
  * @public
5835
5826
  */
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
- )
5827
+ getDroppingOverShape(point: VecLike, droppingShapes: TLShape[] = []) {
5828
+ // starting from the top...
5829
+ const currentPageShapesSorted = this.getCurrentPageShapesSorted()
5830
+ for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
5831
+ const shape = currentPageShapesSorted[i]
5841
5832
 
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
- )
5833
+ if (
5834
+ // ignore hidden shapes
5835
+ this.isShapeHidden(shape) ||
5836
+ // don't allow dropping on selected shapes
5837
+ this.getSelectedShapeIds().includes(shape.id) ||
5838
+ // only allow shapes that can receive children
5839
+ !this.getShapeUtil(shape).canDropShapes(shape, droppingShapes) ||
5840
+ // don't allow dropping a shape on itself or one of it's children
5841
+ droppingShapes.find((s) => s.id === shape.id || this.hasAncestor(shape, s.id))
5842
+ ) {
5843
+ continue
5844
+ }
5845
+
5846
+ // Only allow dropping into the masked page bounds of the shape, e.g. when a frame is
5847
+ // partially clipped by its own parent frame
5848
+ const maskedPageBounds = this.getShapeMaskedPageBounds(shape.id)
5852
5849
 
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
5856
5850
  if (
5857
- shapeUtil.onDragShapesOver ||
5858
- shapeUtil.onDragShapesIn ||
5859
- shapeUtil.onDragShapesOut ||
5860
- shapeUtil.onDropShapesOver
5851
+ maskedPageBounds &&
5852
+ maskedPageBounds.containsPoint(point) &&
5853
+ this.getShapeGeometry(shape).hitTestPoint(this.getPointInShapeSpace(shape, point), 0, true)
5861
5854
  ) {
5862
- return maybeDraggingOverShape
5855
+ return shape
5863
5856
  }
5864
5857
  }
5865
5858
  }
@@ -6218,12 +6211,11 @@ export class Editor extends EventEmitter<TLEventMap> {
6218
6211
  */
6219
6212
  duplicateShapes(shapes: TLShapeId[] | TLShape[], offset?: VecLike): this {
6220
6213
  this.run(() => {
6221
- const _ids =
6214
+ const ids =
6222
6215
  typeof shapes[0] === 'string'
6223
6216
  ? (shapes as TLShapeId[])
6224
6217
  : (shapes as TLShape[]).map((s) => s.id)
6225
6218
 
6226
- const ids = this._shouldIgnoreShapeLock ? _ids : this._getUnlockedShapeIds(_ids)
6227
6219
  if (ids.length <= 0) return this
6228
6220
 
6229
6221
  const initialIds = new Set(ids)
@@ -6303,7 +6295,10 @@ export class Editor extends EventEmitter<TLEventMap> {
6303
6295
  })
6304
6296
  const shapesToCreate = shapesToCreateWithOriginals.map(({ shape }) => shape)
6305
6297
 
6306
- if (!this.canCreateShapes(shapesToCreate)) {
6298
+ const maxShapesReached =
6299
+ shapesToCreate.length + this.getCurrentPageShapeIds().size > this.options.maxShapesPerPage
6300
+
6301
+ if (maxShapesReached) {
6307
6302
  alertMaxShapes(this)
6308
6303
  return
6309
6304
  }
@@ -7732,32 +7727,6 @@ export class Editor extends EventEmitter<TLEventMap> {
7732
7727
  return {}
7733
7728
  }
7734
7729
 
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
-
7761
7730
  /**
7762
7731
  * Create a single shape.
7763
7732
  *
@@ -7804,7 +7773,6 @@ export class Editor extends EventEmitter<TLEventMap> {
7804
7773
  if (maxShapesReached) {
7805
7774
  // can't create more shapes than fit on the page
7806
7775
  alertMaxShapes(this)
7807
- // todo: throw an error here? Otherwise we'll need to check every time whether the shapes were actually created
7808
7776
  return this
7809
7777
  }
7810
7778
 
@@ -7837,10 +7805,9 @@ export class Editor extends EventEmitter<TLEventMap> {
7837
7805
 
7838
7806
  for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
7839
7807
  const parent = currentPageShapesSorted[i]
7840
- const util = this.getShapeUtil(parent)
7841
7808
  if (
7842
- util.canReceiveNewChildrenOfType(parent, partial.type) &&
7843
7809
  !this.isShapeHidden(parent) &&
7810
+ this.getShapeUtil(parent).canReceiveNewChildrenOfType(parent, partial.type) &&
7844
7811
  this.isPointInShape(
7845
7812
  parent,
7846
7813
  // If no parent is provided, then we can treat the
@@ -7859,7 +7826,7 @@ export class Editor extends EventEmitter<TLEventMap> {
7859
7826
 
7860
7827
  const prevParentId = partial.parentId
7861
7828
 
7862
- // a shape cannot be its own parent. This was a rare issue with frames/groups in the syncFuzz tests.
7829
+ // a shape cannot be it's own parent. This was a rare issue with frames/groups in the syncFuzz tests.
7863
7830
  if (parentId === partial.id) {
7864
7831
  parentId = focusedGroupId
7865
7832
  }
@@ -7969,8 +7936,6 @@ export class Editor extends EventEmitter<TLEventMap> {
7969
7936
  }
7970
7937
  })
7971
7938
 
7972
- this.emit('created-shapes', shapeRecordsToCreate)
7973
- this.emit('edit')
7974
7939
  this.store.put(shapeRecordsToCreate)
7975
7940
  })
7976
7941
 
@@ -8365,8 +8330,6 @@ export class Editor extends EventEmitter<TLEventMap> {
8365
8330
  updates.push(updated)
8366
8331
  }
8367
8332
 
8368
- this.emit('edited-shapes', updates)
8369
- this.emit('edit')
8370
8333
  this.store.put(updates)
8371
8334
  })
8372
8335
  }
@@ -8416,8 +8379,6 @@ export class Editor extends EventEmitter<TLEventMap> {
8416
8379
  })
8417
8380
  }
8418
8381
 
8419
- this.emit('deleted-shapes', [...allShapeIdsToDelete])
8420
- this.emit('edit')
8421
8382
  return this.run(() => this.store.remove([...allShapeIdsToDelete]))
8422
8383
  }
8423
8384
 
@@ -9544,8 +9505,6 @@ export class Editor extends EventEmitter<TLEventMap> {
9544
9505
  previousPagePoint,
9545
9506
  currentScreenPoint,
9546
9507
  currentPagePoint,
9547
- originScreenPoint,
9548
- originPagePoint,
9549
9508
  } = this.inputs
9550
9509
 
9551
9510
  const { screenBounds } = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID)!
@@ -9574,8 +9533,8 @@ export class Editor extends EventEmitter<TLEventMap> {
9574
9533
  // Reset velocity on pointer down, or when a pinch starts or ends
9575
9534
  if (info.name === 'pointer_down' || this.inputs.isPinching) {
9576
9535
  pointerVelocity.set(0, 0)
9577
- originScreenPoint.setTo(currentScreenPoint)
9578
- originPagePoint.setTo(currentPagePoint)
9536
+ this.inputs.originScreenPoint.setTo(currentScreenPoint)
9537
+ this.inputs.originPagePoint.setTo(currentPagePoint)
9579
9538
  }
9580
9539
 
9581
9540
  // todo: We only have to do this if there are multiple users in the document
@@ -241,9 +241,7 @@ export class HistoryManager<R extends UnknownRecord> {
241
241
  }
242
242
 
243
243
  bailToMark(id: string) {
244
- if (id) {
245
- this._undo({ pushToRedoStack: false, toMark: id })
246
- }
244
+ this._undo({ pushToRedoStack: false, toMark: id })
247
245
 
248
246
  return this
249
247
  }
@@ -26,7 +26,6 @@ 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. */
30
29
  lineHeight: number
31
30
  /**
32
31
  * When maxWidth is a number, the text will be wrapped to that maxWidth. When maxWidth
@@ -76,7 +75,6 @@ export class TextManager {
76
75
  // we need to save the default styles so that we can restore them when we're done
77
76
  // these must be the css names, not the js names for the styles
78
77
  this.defaultStyles = {
79
- 'overflow-wrap': 'break-word',
80
78
  'word-break': 'auto',
81
79
  width: null,
82
80
  height: null,
@@ -125,7 +123,7 @@ export class TextManager {
125
123
  elm.style.setProperty('font-style', opts.fontStyle)
126
124
  elm.style.setProperty('font-weight', opts.fontWeight)
127
125
  elm.style.setProperty('font-size', opts.fontSize + 'px')
128
- elm.style.setProperty('line-height', opts.lineHeight.toString())
126
+ elm.style.setProperty('line-height', opts.lineHeight * opts.fontSize + 'px')
129
127
  elm.style.setProperty('padding', opts.padding)
130
128
 
131
129
  if (opts.maxWidth) {
@@ -289,7 +287,7 @@ export class TextManager {
289
287
  elm.style.setProperty('font-style', opts.fontStyle)
290
288
  elm.style.setProperty('font-weight', opts.fontWeight)
291
289
  elm.style.setProperty('font-size', opts.fontSize + 'px')
292
- elm.style.setProperty('line-height', opts.lineHeight.toString())
290
+ elm.style.setProperty('line-height', opts.lineHeight * opts.fontSize + 'px')
293
291
 
294
292
  const elementWidth = Math.ceil(opts.width - opts.padding * 2)
295
293
  elm.style.setProperty('width', `${elementWidth}px`)
@@ -4,15 +4,12 @@ import { LegacyMigrations, MigrationSequence } from '@tldraw/store'
4
4
  import {
5
5
  RecordProps,
6
6
  TLHandle,
7
- TLParentId,
8
7
  TLPropsMigrations,
9
8
  TLShape,
10
9
  TLShapeCrop,
11
- TLShapeId,
12
10
  TLShapePartial,
13
11
  TLUnknownShape,
14
12
  } from '@tldraw/tlschema'
15
- import { IndexKey } from '@tldraw/utils'
16
13
  import { ReactElement } from 'react'
17
14
  import { Box, SelectionHandle } from '../../primitives/Box'
18
15
  import { Vec } from '../../primitives/Vec'
@@ -390,6 +387,17 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
390
387
  return false
391
388
  }
392
389
 
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
+
393
401
  /**
394
402
  * Get the shape as an SVG object.
395
403
  *
@@ -509,16 +517,7 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
509
517
  ): Omit<TLShapePartial<Shape>, 'id' | 'type'> | undefined | void
510
518
 
511
519
  /**
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.
520
+ * A callback called when some other shapes are dragged over this one.
522
521
  *
523
522
  * @example
524
523
  *
@@ -532,7 +531,7 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
532
531
  * @param shapes - The shapes that are being dragged over this one.
533
532
  * @public
534
533
  */
535
- onDragShapesOver?(shape: Shape, shapes: TLShape[], info: TLDragShapesOverInfo): void
534
+ onDragShapesOver?(shape: Shape, shapes: TLShape[]): void
536
535
 
537
536
  /**
538
537
  * A callback called when some other shapes are dragged out of this one.
@@ -541,7 +540,7 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
541
540
  * @param shapes - The shapes that are being dragged out.
542
541
  * @public
543
542
  */
544
- onDragShapesOut?(shape: Shape, shapes: TLShape[], info: TLDragShapesOutInfo): void
543
+ onDragShapesOut?(shape: Shape, shapes: TLShape[]): void
545
544
 
546
545
  /**
547
546
  * A callback called when some other shapes are dropped over this one.
@@ -550,7 +549,7 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
550
549
  * @param shapes - The shapes that are being dropped over this one.
551
550
  * @public
552
551
  */
553
- onDropShapesOver?(shape: Shape, shapes: TLShape[], info: TLDropShapesOverInfo): void
552
+ onDropShapesOver?(shape: Shape, shapes: TLShape[]): void
554
553
 
555
554
  /**
556
555
  * A callback called when a shape starts being resized.
@@ -746,37 +745,6 @@ export interface TLCropInfo<T extends TLShape> {
746
745
  crop: TLShapeCrop
747
746
  uncroppedSize: { w: number; h: number }
748
747
  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>
780
748
  }
781
749
 
782
750
  /**
@@ -11,33 +11,29 @@ export class Pointing extends StateNode {
11
11
  static override id = 'pointing'
12
12
 
13
13
  override onPointerMove(info: TLPointerEventInfo) {
14
- const { editor } = this
15
- if (editor.inputs.isDragging) {
16
- const { originPagePoint } = editor.inputs
14
+ if (this.editor.inputs.isDragging) {
15
+ const { originPagePoint } = this.editor.inputs
17
16
 
18
17
  const shapeType = (this.parent as BaseBoxShapeTool)!.shapeType
19
18
 
20
19
  const id = createShapeId()
21
20
 
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,
21
+ const creatingMarkId = this.editor.markHistoryStoppingPoint(`creating_box:${id}`)
22
+ const newPoint = maybeSnapToGrid(originPagePoint, this.editor)
23
+ this.editor
24
+ .createShapes<TLBaseBoxShape>([
25
+ {
26
+ id,
27
+ type: shapeType,
28
+ x: newPoint.x,
29
+ y: newPoint.y,
30
+ props: {
31
+ w: 1,
32
+ h: 1,
33
+ },
35
34
  },
36
- },
37
- ])
38
- const shape = editor.getShape(id)
39
- if (!shape) this.cancel()
40
- editor.select(id)
35
+ ])
36
+ .select(id)
41
37
 
42
38
  const parent = this.parent as BaseBoxShapeTool
43
39
  this.editor.setCurrentTool(
@@ -83,7 +79,6 @@ export class Pointing extends StateNode {
83
79
 
84
80
  this.editor.markHistoryStoppingPoint(`creating_box:${id}`)
85
81
 
86
- // Allow this to trigger the max shapes reached alert
87
82
  // todo: add scale here when dynamic size is enabled (is this still needed?)
88
83
  this.editor.createShapes<TLBaseBoxShape>([
89
84
  {
@@ -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, to: string) {
209
+ exit(info: any, from: 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, to)
214
+ this.onExit?.(info, from)
215
215
 
216
216
  if (!this.getIsActive()) {
217
- this.getCurrent()?.exit(info, to)
217
+ this.getCurrent()?.exit(info, from)
218
218
  }
219
219
  }
220
220
 
@@ -18,10 +18,6 @@ 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: []
25
21
  }
26
22
 
27
23
  /** @public */
@@ -44,7 +44,6 @@ export const Geometry2dFilters: {
44
44
  /** @public */
45
45
  export interface TransformedGeometry2dOptions {
46
46
  isLabel?: boolean
47
- isEmptyLabel?: boolean
48
47
  isInternal?: boolean
49
48
  debugColor?: string
50
49
  ignore?: boolean
@@ -58,24 +57,20 @@ export interface Geometry2dOptions extends TransformedGeometry2dOptions {
58
57
 
59
58
  /** @public */
60
59
  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
62
60
  isFilled = false
63
61
  isClosed = true
64
62
  isLabel = false
65
- isEmptyLabel = false
66
63
  isInternal = false
67
64
  debugColor?: string
68
65
  ignore?: boolean
69
66
 
70
67
  constructor(opts: Geometry2dOptions) {
71
- const { isLabel = false, isEmptyLabel = false, isInternal = false } = opts
72
68
  this.isFilled = opts.isFilled
73
69
  this.isClosed = opts.isClosed
70
+ this.isLabel = opts.isLabel ?? false
71
+ this.isInternal = opts.isInternal ?? false
74
72
  this.debugColor = opts.debugColor
75
73
  this.ignore = opts.ignore
76
- this.isLabel = isLabel
77
- this.isEmptyLabel = isEmptyLabel
78
- this.isInternal = isInternal
79
74
  }
80
75
 
81
76
  isExcludedByFilter(filters?: Geometry2dFilters) {
@@ -17,20 +17,14 @@ export class Group2d extends Geometry2d {
17
17
  ) {
18
18
  super({ ...config, isClosed: true, isFilled: false })
19
19
 
20
- const addChildren = (children: Geometry2d[]) => {
21
- for (const child of children) {
22
- if (child instanceof Group2d) {
23
- addChildren(child.children)
24
- } else if (child.ignore) {
25
- this.ignoredChildren.push(child)
26
- } else {
27
- this.children.push(child)
28
- }
20
+ for (const child of config.children) {
21
+ if (child.ignore) {
22
+ this.ignoredChildren.push(child)
23
+ } else {
24
+ this.children.push(child)
29
25
  }
30
26
  }
31
27
 
32
- addChildren(config.children)
33
-
34
28
  if (this.children.length === 0) throw Error('Group2d must have at least one child')
35
29
  }
36
30
 
@@ -18,7 +18,7 @@ import { debugFlags, pointerCaptureTrackingObject } from './debug-flags'
18
18
 
19
19
  /** @public */
20
20
  export function loopToHtmlElement(elm: Element): HTMLElement {
21
- if (elm.nodeType === Node.ELEMENT_NODE) return elm as HTMLElement
21
+ if (elm instanceof HTMLElement) return elm
22
22
  if (elm.parentElement) return loopToHtmlElement(elm.parentElement)
23
23
  else throw Error('Could not find a parent element of an HTML type!')
24
24
  }
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 = '3.14.0-canary.e989a4107be2'
4
+ export const version = '3.14.0-canary.ea2c4acfa022'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2025-07-01T08:28:05.164Z',
8
- patch: '2025-07-01T08:28:05.164Z',
7
+ minor: '2025-06-18T12:54:08.671Z',
8
+ patch: '2025-06-18T12:54:08.671Z',
9
9
  }