@tldraw/editor 5.2.0-canary.fe03bcdddf34 → 5.2.0-canary.fff413eea248

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 (87) hide show
  1. package/README.md +7 -1
  2. package/dist-cjs/index.d.ts +43 -47
  3. package/dist-cjs/index.js +4 -4
  4. package/dist-cjs/index.js.map +2 -2
  5. package/dist-cjs/lib/editor/Editor.js +92 -53
  6. package/dist-cjs/lib/editor/Editor.js.map +3 -3
  7. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +8 -58
  8. package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
  9. package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js +3 -3
  10. package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js.map +2 -2
  11. package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js +1 -2
  12. package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +2 -2
  13. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +12 -2
  14. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +2 -2
  15. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +4 -2
  16. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +2 -2
  17. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +7 -3
  18. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  19. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +15 -2
  20. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  21. package/dist-cjs/lib/editor/overlays/strokeShapeIndicators.js +79 -0
  22. package/dist-cjs/lib/editor/overlays/strokeShapeIndicators.js.map +7 -0
  23. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +3 -0
  24. package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +2 -2
  25. package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
  26. package/dist-cjs/lib/editor/types/event-types.js +0 -2
  27. package/dist-cjs/lib/editor/types/event-types.js.map +2 -2
  28. package/dist-cjs/lib/hooks/usePresence.js.map +2 -2
  29. package/dist-cjs/version.js +3 -3
  30. package/dist-cjs/version.js.map +1 -1
  31. package/dist-esm/index.d.mts +43 -47
  32. package/dist-esm/index.mjs +5 -7
  33. package/dist-esm/index.mjs.map +2 -2
  34. package/dist-esm/lib/editor/Editor.mjs +92 -53
  35. package/dist-esm/lib/editor/Editor.mjs.map +3 -3
  36. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +8 -58
  37. package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
  38. package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs +3 -3
  39. package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs.map +2 -2
  40. package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs +1 -2
  41. package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +2 -2
  42. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +12 -2
  43. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +2 -2
  44. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +4 -2
  45. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +2 -2
  46. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +7 -3
  47. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  48. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +15 -2
  49. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  50. package/dist-esm/lib/editor/overlays/strokeShapeIndicators.mjs +59 -0
  51. package/dist-esm/lib/editor/overlays/strokeShapeIndicators.mjs.map +7 -0
  52. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +3 -0
  53. package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +2 -2
  54. package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
  55. package/dist-esm/lib/editor/types/event-types.mjs +0 -2
  56. package/dist-esm/lib/editor/types/event-types.mjs.map +2 -2
  57. package/dist-esm/lib/hooks/usePresence.mjs.map +2 -2
  58. package/dist-esm/version.mjs +3 -3
  59. package/dist-esm/version.mjs.map +1 -1
  60. package/editor.css +2 -0
  61. package/package.json +8 -8
  62. package/src/index.ts +2 -5
  63. package/src/lib/editor/Editor.ts +124 -64
  64. package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +54 -74
  65. package/src/lib/editor/managers/ClickManager/ClickManager.ts +15 -65
  66. package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.test.ts +43 -16
  67. package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.ts +8 -5
  68. package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +4 -4
  69. package/src/lib/editor/managers/FocusManager/FocusManager.ts +1 -2
  70. package/src/lib/editor/managers/FontManager/FontManager.test.ts +13 -9
  71. package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +20 -2
  72. package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +9 -2
  73. package/src/lib/editor/managers/TextManager/TextManager.test.ts +16 -14
  74. package/src/lib/editor/managers/TextManager/TextManager.ts +17 -2
  75. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +12 -2
  76. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +27 -2
  77. package/src/lib/editor/overlays/strokeShapeIndicators.ts +86 -0
  78. package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +4 -0
  79. package/src/lib/editor/tools/StateNode.ts +0 -2
  80. package/src/lib/editor/types/event-types.ts +2 -6
  81. package/src/lib/hooks/usePresence.ts +2 -2
  82. package/src/version.ts +3 -3
  83. package/dist-cjs/lib/editor/overlays/ShapeIndicatorOverlayUtil.js +0 -161
  84. package/dist-cjs/lib/editor/overlays/ShapeIndicatorOverlayUtil.js.map +0 -7
  85. package/dist-esm/lib/editor/overlays/ShapeIndicatorOverlayUtil.mjs +0 -141
  86. package/dist-esm/lib/editor/overlays/ShapeIndicatorOverlayUtil.mjs.map +0 -7
  87. package/src/lib/editor/overlays/ShapeIndicatorOverlayUtil.ts +0 -216
@@ -3068,8 +3068,8 @@ export class Editor extends EventEmitter<TLEventMap> {
3068
3068
  return baseCamera
3069
3069
  }
3070
3070
 
3071
- private _getFollowingPresence(targetUserId: string | null) {
3072
- const visited = [this.user.getId()]
3071
+ private _getFollowingPresence(targetUserId: TLUserId | null) {
3072
+ const visited = [this.user.getRecordId()]
3073
3073
  const collaborators = this.getCollaborators()
3074
3074
  let leaderPresence = null as null | TLInstancePresence
3075
3075
  while (targetUserId && !visited.includes(targetUserId)) {
@@ -3336,6 +3336,15 @@ export class Editor extends EventEmitter<TLEventMap> {
3336
3336
 
3337
3337
  let { x, y, z = currentCamera.z } = point
3338
3338
 
3339
+ // `requested` kept the caller's focal point (e.g. the cursor) fixed at
3340
+ // zoom `rz`. When `rz` gets clamped, keep that same focal point fixed at
3341
+ // the clamped zoom `z` rather than snapping to the viewport center.
3342
+ const preserveFocalPoint = (current: number, requested: number, rz: number, z: number) => {
3343
+ const cz = currentCamera.z
3344
+ if (rz === cz) return current
3345
+ return current + ((requested - current) * (1 / z - 1 / cz)) / (1 / rz - 1 / cz)
3346
+ }
3347
+
3339
3348
  // If force is true, then we'll set the camera to the point regardless of
3340
3349
  // the camera options, so that we can handle gestures that permit elasticity
3341
3350
  // or decay, or animations that occur while the camera is locked.
@@ -3378,17 +3387,14 @@ export class Editor extends EventEmitter<TLEventMap> {
3378
3387
  }
3379
3388
 
3380
3389
  if (z < minZ || z > maxZ) {
3381
- // We're trying to zoom out past the minimum zoom level,
3382
- // or in past the maximum zoom level, so stop the camera
3383
- // but keep the current center
3384
- const { x: cx, y: cy, z: cz } = currentCamera
3385
- const cxA = -cx + vsb.w / cz / 2
3386
- const cyA = -cy + vsb.h / cz / 2
3390
+ // We're trying to zoom out past the minimum zoom level, or in
3391
+ // past the maximum zoom level, so clamp the zoom while keeping
3392
+ // the caller's focal point fixed. Axis constraints below still
3393
+ // apply on top of this.
3394
+ const rz = z
3387
3395
  z = clamp(z, minZ, maxZ)
3388
- const cxB = -cx + vsb.w / z / 2
3389
- const cyB = -cy + vsb.h / z / 2
3390
- x = cx + cxB - cxA
3391
- y = cy + cyB - cyA
3396
+ x = preserveFocalPoint(currentCamera.x, x, rz, z)
3397
+ y = preserveFocalPoint(currentCamera.y, y, rz, z)
3392
3398
  }
3393
3399
 
3394
3400
  // Calculate available space
@@ -3477,12 +3483,12 @@ export class Editor extends EventEmitter<TLEventMap> {
3477
3483
  }
3478
3484
  }
3479
3485
  } else {
3480
- // constrain the zoom, preserving the center
3486
+ // constrain the zoom, keeping the caller's focal point fixed
3481
3487
  if (z > zoomMax || z < zoomMin) {
3482
- const { x: cx, y: cy, z: cz } = currentCamera
3488
+ const rz = z
3483
3489
  z = clamp(z, zoomMin, zoomMax)
3484
- x = cx + (-cx + vsb.w / z / 2) - (-cx + vsb.w / cz / 2)
3485
- y = cy + (-cy + vsb.h / z / 2) - (-cy + vsb.h / cz / 2)
3490
+ x = preserveFocalPoint(currentCamera.x, x, rz, z)
3491
+ y = preserveFocalPoint(currentCamera.y, y, rz, z)
3486
3492
  }
3487
3493
  }
3488
3494
  }
@@ -4023,16 +4029,34 @@ export class Editor extends EventEmitter<TLEventMap> {
4023
4029
 
4024
4030
  this.once('stop-camera-animation', cancel)
4025
4031
 
4032
+ const dirZ = direction.z ?? 0
4033
+
4026
4034
  const moveCamera = (elapsed: number) => {
4027
4035
  const { x: cx, y: cy, z: cz } = this.getCamera()
4028
- const movementVec = Vec.Mul(direction, (currentSpeed * elapsed) / cz)
4036
+
4037
+ // Pan movement from x/y direction
4038
+ const dx = (direction.x * (currentSpeed * elapsed)) / cz
4039
+ const dy = (direction.y * (currentSpeed * elapsed)) / cz
4040
+
4041
+ let newCx = cx + dx
4042
+ let newCy = cy + dy
4043
+ let newCz = cz
4044
+
4045
+ // animate zoom if z direction is passed in
4046
+ if (dirZ !== 0) {
4047
+ newCz = cz * (1 + dirZ * currentSpeed * elapsed)
4048
+ // Adjust x/y to keep the viewport center fixed while zooming
4049
+ const center = this.getViewportScreenCenter()
4050
+ newCx += center.x / newCz - center.x / cz
4051
+ newCy += center.y / newCz - center.y / cz
4052
+ }
4029
4053
 
4030
4054
  // Apply friction
4031
4055
  currentSpeed *= 1 - friction
4032
4056
  if (currentSpeed < speedThreshold) {
4033
4057
  cancel()
4034
4058
  } else {
4035
- this._setCamera(new Vec(cx + movementVec.x, cy + movementVec.y, cz))
4059
+ this._setCamera(new Vec(newCx, newCy, newCz))
4036
4060
  }
4037
4061
  }
4038
4062
 
@@ -4054,7 +4078,7 @@ export class Editor extends EventEmitter<TLEventMap> {
4054
4078
  * @param opts - The camera move options.
4055
4079
  * @public
4056
4080
  */
4057
- zoomToUser(userId: string, opts: TLCameraMoveOptions = { animation: { duration: 500 } }): this {
4081
+ zoomToUser(userId: TLUserId, opts: TLCameraMoveOptions = { animation: { duration: 500 } }): this {
4058
4082
  const presence = this.getCollaborators().find((c) => c.userId === userId)
4059
4083
 
4060
4084
  if (!presence) return this
@@ -4426,11 +4450,11 @@ export class Editor extends EventEmitter<TLEventMap> {
4426
4450
  *
4427
4451
  * @public
4428
4452
  */
4429
- startFollowingUser(userId: string): this {
4453
+ startFollowingUser(userId: TLUserId): this {
4430
4454
  // if we were already following someone, stop following them
4431
4455
  this.stopFollowingUser()
4432
4456
 
4433
- const thisUserId = this.user.getId()
4457
+ const thisUserId = this.user.getExternalId()
4434
4458
 
4435
4459
  if (!thisUserId) {
4436
4460
  console.warn('You should set the userId for the current instance before following a user')
@@ -8078,32 +8102,53 @@ export class Editor extends EventEmitter<TLEventMap> {
8078
8102
  * @public
8079
8103
  */
8080
8104
  resizeShape(shape: TLShapeId | TLShape, scale: VecLike, opts: TLResizeShapeOptions = {}): this {
8105
+ const partial = this.getResizeShapePartial(shape, scale, opts)
8106
+ if (partial) this.updateShapes([partial])
8107
+ return this
8108
+ }
8109
+
8110
+ /**
8111
+ * Get the update for a resized shape without committing it to the store. Interactions that
8112
+ * resize many shapes at once use this to collect all of the updates and commit them in a
8113
+ * single batch. Returns null when there is nothing to update.
8114
+ *
8115
+ * Shapes that are rotated out of alignment with the scale axis cannot be resized with a
8116
+ * single update; those shapes are resized immediately (as `resizeShape` would do) and null
8117
+ * is returned.
8118
+ *
8119
+ * @internal
8120
+ */
8121
+ getResizeShapePartial(
8122
+ shape: TLShapeId | TLShape,
8123
+ scale: VecLike,
8124
+ opts: TLResizeShapeOptions = {}
8125
+ ): TLShapePartial | null {
8081
8126
  const id = typeof shape === 'string' ? shape : shape.id
8082
- if (this.getIsReadonly()) return this
8127
+ if (this.getIsReadonly()) return null
8083
8128
 
8084
8129
  if (!Number.isFinite(scale.x)) scale = new Vec(1, scale.y)
8085
8130
  if (!Number.isFinite(scale.y)) scale = new Vec(scale.x, 1)
8086
8131
 
8087
8132
  const initialShape = opts.initialShape ?? this.getShape(id)
8088
- if (!initialShape) return this
8133
+ if (!initialShape) return null
8089
8134
 
8090
8135
  const scaleOrigin = opts.scaleOrigin ?? this.getShapePageBounds(id)?.center
8091
- if (!scaleOrigin) return this
8136
+ if (!scaleOrigin) return null
8092
8137
 
8093
8138
  const pageTransform = opts.initialPageTransform
8094
8139
  ? Mat.Cast(opts.initialPageTransform)
8095
8140
  : this.getShapePageTransform(id)
8096
- if (!pageTransform) return this
8141
+ if (!pageTransform) return null
8097
8142
 
8098
8143
  const pageRotation = pageTransform.rotation()
8099
8144
 
8100
- if (pageRotation == null) return this
8145
+ if (pageRotation == null) return null
8101
8146
 
8102
8147
  const scaleAxisRotation = opts.scaleAxisRotation ?? pageRotation
8103
8148
 
8104
8149
  const initialBounds = opts.initialBounds ?? this.getShapeGeometry(id).bounds
8105
8150
 
8106
- if (!initialBounds) return this
8151
+ if (!initialBounds) return null
8107
8152
 
8108
8153
  const isAspectRatioLocked =
8109
8154
  opts.isAspectRatioLocked ?? this.getShapeUtil(initialShape).isAspectRatioLocked(initialShape)
@@ -8113,7 +8158,7 @@ export class Editor extends EventEmitter<TLEventMap> {
8113
8158
  // from whichever axis is being scaled the least, to avoid the shape getting bigger
8114
8159
  // than the bounds of the selection
8115
8160
  // const minScale = Math.min(Math.abs(scale.x), Math.abs(scale.y))
8116
- return this._resizeUnalignedShape(id, scale, {
8161
+ this._resizeUnalignedShape(id, scale, {
8117
8162
  ...opts,
8118
8163
  initialBounds,
8119
8164
  scaleOrigin,
@@ -8122,6 +8167,7 @@ export class Editor extends EventEmitter<TLEventMap> {
8122
8167
  isAspectRatioLocked,
8123
8168
  initialShape,
8124
8169
  })
8170
+ return null
8125
8171
  }
8126
8172
 
8127
8173
  const util = this.getShapeUtil(initialShape)
@@ -8134,7 +8180,7 @@ export class Editor extends EventEmitter<TLEventMap> {
8134
8180
  }
8135
8181
  }
8136
8182
 
8137
- let didResize = false
8183
+ let workingShape: TLShape | null = null
8138
8184
 
8139
8185
  if (util.onResize && util.canResize(initialShape)) {
8140
8186
  // get the model changes from the shape util
@@ -8166,7 +8212,7 @@ export class Editor extends EventEmitter<TLEventMap> {
8166
8212
  // need to adjust the shape's x and y points in case the parent has moved since start of resizing
8167
8213
  const { x, y } = this.getPointInParentSpace(initialShape.id, initialPagePoint)
8168
8214
 
8169
- let workingShape = initialShape
8215
+ workingShape = initialShape
8170
8216
  if (!opts.skipStartAndEndCallbacks) {
8171
8217
  workingShape = applyPartialToRecordWithProps(
8172
8218
  initialShape,
@@ -8188,10 +8234,6 @@ export class Editor extends EventEmitter<TLEventMap> {
8188
8234
  }
8189
8235
  )
8190
8236
 
8191
- if (resizedShape) {
8192
- didResize = true
8193
- }
8194
-
8195
8237
  workingShape = applyPartialToRecordWithProps(workingShape, {
8196
8238
  id,
8197
8239
  type: initialShape.type as any,
@@ -8207,40 +8249,47 @@ export class Editor extends EventEmitter<TLEventMap> {
8207
8249
  )
8208
8250
  }
8209
8251
 
8210
- this.updateShapes([workingShape])
8252
+ if (resizedShape) {
8253
+ return workingShape
8254
+ }
8211
8255
  }
8212
8256
 
8213
- if (!didResize) {
8214
- // reposition shape (rather than resizing it) based on where its resized center would be
8257
+ // the shape was not resized by its util, so reposition it (rather than resizing it)
8258
+ // based on where its resized center would be
8215
8259
 
8216
- const initialPageCenter = Mat.applyToPoint(pageTransform, initialBounds.center)
8217
- // get the model changes from the shape util
8218
- const newPageCenter = this._scalePagePoint(
8219
- initialPageCenter,
8220
- scaleOrigin,
8221
- scale,
8222
- scaleAxisRotation
8223
- )
8260
+ const initialPageCenter = Mat.applyToPoint(pageTransform, initialBounds.center)
8261
+ // get the model changes from the shape util
8262
+ const newPageCenter = this._scalePagePoint(
8263
+ initialPageCenter,
8264
+ scaleOrigin,
8265
+ scale,
8266
+ scaleAxisRotation
8267
+ )
8224
8268
 
8225
- const initialPageCenterInParentSpace = this.getPointInParentSpace(
8226
- initialShape.id,
8227
- initialPageCenter
8228
- )
8229
- const newPageCenterInParentSpace = this.getPointInParentSpace(initialShape.id, newPageCenter)
8269
+ const initialPageCenterInParentSpace = this.getPointInParentSpace(
8270
+ initialShape.id,
8271
+ initialPageCenter
8272
+ )
8273
+ const newPageCenterInParentSpace = this.getPointInParentSpace(initialShape.id, newPageCenter)
8230
8274
 
8231
- const delta = Vec.Sub(newPageCenterInParentSpace, initialPageCenterInParentSpace)
8232
- // apply the changes to the model
8233
- this.updateShapes([
8234
- {
8235
- id,
8236
- type: initialShape.type as any,
8237
- x: initialShape.x + delta.x,
8238
- y: initialShape.y + delta.y,
8239
- },
8240
- ])
8275
+ const delta = Vec.Sub(newPageCenterInParentSpace, initialPageCenterInParentSpace)
8276
+
8277
+ if (workingShape) {
8278
+ // the util's onResize ran but returned no change; keep the working update (which may
8279
+ // include changes from onResizeStart / onResizeEnd) and reposition the shape
8280
+ return {
8281
+ ...workingShape,
8282
+ x: initialShape.x + delta.x,
8283
+ y: initialShape.y + delta.y,
8284
+ }
8241
8285
  }
8242
8286
 
8243
- return this
8287
+ return {
8288
+ id,
8289
+ type: initialShape.type as any,
8290
+ x: initialShape.x + delta.x,
8291
+ y: initialShape.y + delta.y,
8292
+ }
8244
8293
  }
8245
8294
 
8246
8295
  /** @internal */
@@ -11167,7 +11216,12 @@ export class Editor extends EventEmitter<TLEventMap> {
11167
11216
  inputs.setIsDragging(false)
11168
11217
 
11169
11218
  // If pen mode is off but we're not already in pen mode, turn that on
11170
- if (!isPenMode && isPen) this.updateInstanceState({ isPenMode: true })
11219
+ if (!isPenMode && isPen) {
11220
+ this.updateInstanceState({ isPenMode: true })
11221
+ // Once pen mode is on, touch input is ignored, so we discard the
11222
+ // in-progress touch interaction .
11223
+ this.interrupt()
11224
+ }
11171
11225
 
11172
11226
  // On devices with erasers (like the Surface Pen or Wacom Pen), button 5 is the eraser
11173
11227
  if (info.button === STYLUS_ERASER_BUTTON) {
@@ -11317,7 +11371,10 @@ export class Editor extends EventEmitter<TLEventMap> {
11317
11371
  // Don't pass right-click panning events to the state chart
11318
11372
  // as it causes unintended shape selection on release
11319
11373
  if (slideSpeed > 0) {
11320
- this.slideCamera({ speed: slideSpeed, direction: slideDirection })
11374
+ this.slideCamera({
11375
+ speed: slideSpeed,
11376
+ direction: { x: slideDirection.x, y: slideDirection.y, z: 0 },
11377
+ })
11321
11378
  }
11322
11379
  this._selectedShapeIdsAtPointerDown = []
11323
11380
  this._didCaptureSelectionAtPointerDown = false
@@ -11326,7 +11383,10 @@ export class Editor extends EventEmitter<TLEventMap> {
11326
11383
  }
11327
11384
 
11328
11385
  if (slideSpeed > 0) {
11329
- this.slideCamera({ speed: slideSpeed, direction: slideDirection })
11386
+ this.slideCamera({
11387
+ speed: slideSpeed,
11388
+ direction: { x: slideDirection.x, y: slideDirection.y, z: 0 },
11389
+ })
11330
11390
  }
11331
11391
  } else {
11332
11392
  if (info.button === STYLUS_ERASER_BUTTON) {
@@ -122,7 +122,7 @@ describe('ClickManager', () => {
122
122
  expect(result.type).toBe('click')
123
123
  expect(result.name).toBe('double_click')
124
124
  expect(result.phase).toBe('down')
125
- expect(clickManager.clickState).toBe('pendingTriple')
125
+ expect(clickManager.clickState).toBe('pendingOverflow')
126
126
  })
127
127
 
128
128
  it('should generate double_click up event on pointer_up after double_click down', () => {
@@ -139,12 +139,34 @@ describe('ClickManager', () => {
139
139
  expect(result.phase).toBe('up')
140
140
  })
141
141
 
142
- it('should dispatch double_click settle event after timeout in pendingTriple', () => {
142
+ it('should dispatch double_click settle-down event after timeout in pendingOverflow (pointer held)', () => {
143
143
  const firstDown = createPointerEvent('pointer_down', { x: 100, y: 100 })
144
144
  const secondDown = createPointerEvent('pointer_down', { x: 100, y: 100 })
145
145
 
146
146
  clickManager.handlePointerEvent(firstDown)
147
147
  clickManager.handlePointerEvent(secondDown)
148
+ // no pointer_up between or after — pointer is still down at settle time
149
+
150
+ vi.advanceTimersByTime(350)
151
+
152
+ expect(editor.dispatch).toHaveBeenCalledWith(
153
+ expect.objectContaining({
154
+ type: 'click',
155
+ name: 'double_click',
156
+ phase: 'settle-down',
157
+ })
158
+ )
159
+ expect(clickManager.clickState).toBe('idle')
160
+ })
161
+
162
+ it('should dispatch double_click settle-up event after timeout in pendingOverflow (pointer released)', () => {
163
+ const down = createPointerEvent('pointer_down', { x: 100, y: 100 })
164
+ const up = createPointerEvent('pointer_up', { x: 100, y: 100 })
165
+
166
+ clickManager.handlePointerEvent(down)
167
+ clickManager.handlePointerEvent(up)
168
+ clickManager.handlePointerEvent(down)
169
+ clickManager.handlePointerEvent(up)
148
170
 
149
171
  vi.advanceTimersByTime(350)
150
172
 
@@ -152,124 +174,84 @@ describe('ClickManager', () => {
152
174
  expect.objectContaining({
153
175
  type: 'click',
154
176
  name: 'double_click',
155
- phase: 'settle',
177
+ phase: 'settle-up',
156
178
  })
157
179
  )
158
180
  expect(clickManager.clickState).toBe('idle')
159
181
  })
160
182
  })
161
183
 
162
- describe('triple and quadruple click detection', () => {
163
- it('should detect triple click on third pointer_down', () => {
184
+ describe('overflow click handling', () => {
185
+ it('should enter overflow on the third pointer_down without emitting another click', () => {
164
186
  const firstDown = createPointerEvent('pointer_down', { x: 100, y: 100 })
165
187
  const secondDown = createPointerEvent('pointer_down', { x: 100, y: 100 })
166
188
  const thirdDown = createPointerEvent('pointer_down', { x: 100, y: 100 })
167
189
 
168
190
  clickManager.handlePointerEvent(firstDown)
169
191
  clickManager.handlePointerEvent(secondDown)
170
- const result = clickManager.handlePointerEvent(thirdDown) as TLClickEventInfo
192
+ const result = clickManager.handlePointerEvent(thirdDown)
171
193
 
172
- expect(result.type).toBe('click')
173
- expect(result.name).toBe('triple_click')
174
- expect(result.phase).toBe('down')
175
- expect(clickManager.clickState).toBe('pendingQuadruple')
194
+ expect(result).toBe(thirdDown)
195
+ expect(clickManager.clickState).toBe('overflow')
176
196
  })
177
197
 
178
- it('should detect quadruple click on fourth pointer_down', () => {
198
+ it('should keep overflow active on further clicks', () => {
179
199
  const pointerDown = createPointerEvent('pointer_down', { x: 100, y: 100 })
180
200
 
181
201
  clickManager.handlePointerEvent(pointerDown) // first
182
202
  clickManager.handlePointerEvent(pointerDown) // second (double_click)
183
- clickManager.handlePointerEvent(pointerDown) // third (triple_click)
184
- const result = clickManager.handlePointerEvent(pointerDown) as TLClickEventInfo // fourth
185
-
186
- expect(result.type).toBe('click')
187
- expect(result.name).toBe('quadruple_click')
188
- expect(result.phase).toBe('down')
189
- expect(clickManager.clickState).toBe('pendingOverflow')
190
- })
191
-
192
- it('should handle overflow state after quadruple click', () => {
193
- const pointerDown = createPointerEvent('pointer_down', { x: 100, y: 100 })
194
-
195
- clickManager.handlePointerEvent(pointerDown) // first
196
- clickManager.handlePointerEvent(pointerDown) // second
197
- clickManager.handlePointerEvent(pointerDown) // third
198
- clickManager.handlePointerEvent(pointerDown) // fourth
199
- const result = clickManager.handlePointerEvent(pointerDown) // fifth
203
+ clickManager.handlePointerEvent(pointerDown) // third (overflow)
204
+ const result = clickManager.handlePointerEvent(pointerDown) // fourth
200
205
 
201
206
  expect(result).toBe(pointerDown)
202
207
  expect(clickManager.clickState).toBe('overflow')
203
208
  })
204
209
 
205
- it('should generate triple_click up event on pointer_up after triple_click down', () => {
206
- const pointerDown = createPointerEvent('pointer_down', { x: 100, y: 100 })
207
- const pointerUp = createPointerEvent('pointer_up', { x: 100, y: 100 })
208
-
209
- clickManager.handlePointerEvent(pointerDown) // first
210
- clickManager.handlePointerEvent(pointerDown) // second
211
- clickManager.handlePointerEvent(pointerDown) // third
212
- const result = clickManager.handlePointerEvent(pointerUp) as TLClickEventInfo
213
-
214
- expect(result.type).toBe('click')
215
- expect(result.name).toBe('triple_click')
216
- expect(result.phase).toBe('up')
217
- })
218
-
219
- it('should generate quadruple_click up event on pointer_up after quadruple_click down', () => {
210
+ it('should not emit double_click up events while in overflow', () => {
220
211
  const pointerDown = createPointerEvent('pointer_down', { x: 100, y: 100 })
221
212
  const pointerUp = createPointerEvent('pointer_up', { x: 100, y: 100 })
222
213
 
223
214
  clickManager.handlePointerEvent(pointerDown) // first
224
215
  clickManager.handlePointerEvent(pointerDown) // second
225
216
  clickManager.handlePointerEvent(pointerDown) // third
226
- clickManager.handlePointerEvent(pointerDown) // fourth
227
- const result = clickManager.handlePointerEvent(pointerUp) as TLClickEventInfo
217
+ const result = clickManager.handlePointerEvent(pointerUp)
228
218
 
229
- expect(result.type).toBe('click')
230
- expect(result.name).toBe('quadruple_click')
231
- expect(result.phase).toBe('up')
219
+ expect(result).toBe(pointerUp)
220
+ expect(clickManager.clickState).toBe('overflow')
232
221
  })
233
- })
234
222
 
235
- describe('timeout behavior and settle events', () => {
236
- it('should dispatch triple_click settle event after timeout in pendingQuadruple', () => {
223
+ it('should return to idle after overflow timeout without dispatching a settle event', () => {
237
224
  const pointerDown = createPointerEvent('pointer_down', { x: 100, y: 100 })
238
225
 
239
226
  clickManager.handlePointerEvent(pointerDown) // first
240
227
  clickManager.handlePointerEvent(pointerDown) // second
241
- clickManager.handlePointerEvent(pointerDown) // third
228
+ clickManager.handlePointerEvent(pointerDown) // third -> overflow
242
229
 
243
230
  vi.advanceTimersByTime(350)
244
231
 
245
- expect(editor.dispatch).toHaveBeenCalledWith(
246
- expect.objectContaining({
247
- type: 'click',
248
- name: 'triple_click',
249
- phase: 'settle',
250
- })
251
- )
232
+ expect(editor.dispatch).not.toHaveBeenCalled()
252
233
  expect(clickManager.clickState).toBe('idle')
253
234
  })
235
+ })
254
236
 
255
- it('should dispatch quadruple_click settle event after timeout in pendingOverflow', () => {
256
- const pointerDown = createPointerEvent('pointer_down', { x: 100, y: 100 })
237
+ describe('timeout behavior and settle events', () => {
238
+ it('should track press/release state across the pending window (settle-down then release → settle-up)', () => {
239
+ const down = createPointerEvent('pointer_down', { x: 100, y: 100 })
240
+ const up = createPointerEvent('pointer_up', { x: 100, y: 100 })
257
241
 
258
- clickManager.handlePointerEvent(pointerDown) // first
259
- clickManager.handlePointerEvent(pointerDown) // second
260
- clickManager.handlePointerEvent(pointerDown) // third
261
- clickManager.handlePointerEvent(pointerDown) // fourth
242
+ clickManager.handlePointerEvent(down)
243
+ clickManager.handlePointerEvent(up)
244
+ clickManager.handlePointerEvent(down) // second press — pointer is down...
245
+ clickManager.handlePointerEvent(up) // ...but released before timeout
262
246
 
263
247
  vi.advanceTimersByTime(350)
264
248
 
265
249
  expect(editor.dispatch).toHaveBeenCalledWith(
266
250
  expect.objectContaining({
267
- type: 'click',
268
- name: 'quadruple_click',
269
- phase: 'settle',
251
+ name: 'double_click',
252
+ phase: 'settle-up',
270
253
  })
271
254
  )
272
- expect(clickManager.clickState).toBe('idle')
273
255
  })
274
256
 
275
257
  it('should use different timeout durations for different states', () => {
@@ -316,7 +298,7 @@ describe('ClickManager', () => {
316
298
 
317
299
  expect(result.type).toBe('click')
318
300
  expect(result.name).toBe('double_click')
319
- expect(clickManager.clickState).toBe('pendingTriple')
301
+ expect(clickManager.clickState).toBe('pendingOverflow')
320
302
  })
321
303
  })
322
304
 
@@ -396,7 +378,7 @@ describe('ClickManager', () => {
396
378
 
397
379
  clickManager.handlePointerEvent(pointerDown)
398
380
  clickManager.handlePointerEvent(pointerDown) // double click
399
- expect(clickManager.clickState).toBe('pendingTriple')
381
+ expect(clickManager.clickState).toBe('pendingOverflow')
400
382
 
401
383
  clickManager.cancelDoubleClickTimeout()
402
384
 
@@ -416,9 +398,7 @@ describe('ClickManager', () => {
416
398
  // Get to overflow state
417
399
  clickManager.handlePointerEvent(pointerDown) // 1
418
400
  clickManager.handlePointerEvent(pointerDown) // 2
419
- clickManager.handlePointerEvent(pointerDown) // 3
420
- clickManager.handlePointerEvent(pointerDown) // 4
421
- clickManager.handlePointerEvent(pointerDown) // 5 -> overflow
401
+ clickManager.handlePointerEvent(pointerDown) // 3 -> overflow
422
402
 
423
403
  expect(clickManager.clickState).toBe('overflow')
424
404