@tldraw/editor 3.16.0-canary.8c74738e06fb → 3.16.0-canary.a03de714c746

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 (52) hide show
  1. package/dist-cjs/index.d.ts +60 -9
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +1 -1
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/MenuClickCapture.js +5 -0
  7. package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
  8. package/dist-cjs/lib/config/TLUserPreferences.js +8 -2
  9. package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
  10. package/dist-cjs/lib/editor/Editor.js +19 -9
  11. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  12. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +8 -3
  13. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  14. package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
  15. package/dist-cjs/lib/hooks/useCanvasEvents.js +20 -24
  16. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  17. package/dist-cjs/lib/options.js +1 -0
  18. package/dist-cjs/lib/options.js.map +2 -2
  19. package/dist-cjs/version.js +3 -3
  20. package/dist-cjs/version.js.map +1 -1
  21. package/dist-esm/index.d.mts +60 -9
  22. package/dist-esm/index.mjs +1 -1
  23. package/dist-esm/index.mjs.map +2 -2
  24. package/dist-esm/lib/TldrawEditor.mjs +1 -1
  25. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  26. package/dist-esm/lib/components/MenuClickCapture.mjs +5 -0
  27. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  28. package/dist-esm/lib/config/TLUserPreferences.mjs +8 -2
  29. package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
  30. package/dist-esm/lib/editor/Editor.mjs +19 -9
  31. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  32. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +8 -3
  33. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  34. package/dist-esm/lib/hooks/useCanvasEvents.mjs +21 -25
  35. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  36. package/dist-esm/lib/options.mjs +1 -0
  37. package/dist-esm/lib/options.mjs.map +2 -2
  38. package/dist-esm/version.mjs +3 -3
  39. package/dist-esm/version.mjs.map +1 -1
  40. package/editor.css +2 -0
  41. package/package.json +7 -7
  42. package/src/index.ts +1 -0
  43. package/src/lib/TldrawEditor.tsx +5 -5
  44. package/src/lib/components/MenuClickCapture.tsx +8 -0
  45. package/src/lib/config/TLUserPreferences.ts +7 -0
  46. package/src/lib/editor/Editor.ts +33 -27
  47. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +13 -0
  48. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +5 -0
  49. package/src/lib/editor/types/misc-types.ts +54 -1
  50. package/src/lib/hooks/useCanvasEvents.ts +32 -39
  51. package/src/lib/options.ts +2 -0
  52. package/src/version.ts +3 -3
@@ -1,4 +1,4 @@
1
- import { BoxModel } from '@tldraw/tlschema'
1
+ import { BoxModel, TLShape } from '@tldraw/tlschema'
2
2
  import { Box } from '../../primitives/Box'
3
3
  import { VecLike } from '../../primitives/Vec'
4
4
 
@@ -206,3 +206,56 @@ export interface TLUpdatePointerOptions {
206
206
  isPen?: boolean
207
207
  button?: number
208
208
  }
209
+
210
+ /**
211
+ * Options to {@link Editor.getShapeAtPoint}.
212
+ *
213
+ * @public
214
+ */
215
+ export interface TLGetShapeAtPointOptions {
216
+ /**
217
+ * The margin to apply to the shape.
218
+ * If a number, it will be applied to both the inside and outside of the shape.
219
+ * If an array, the first element will be applied to the inside of the shape, and the second element will be applied to the outside.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * // Get the shape at the center of the screen
224
+ * const shape = editor.getShapeAtProps({
225
+ * margin: 10,
226
+ * })
227
+ *
228
+ * // Get the shape at the center of the screen with a 10px inner margin and a 5px outer margin
229
+ * const shape = editor.getShapeAtProps({
230
+ * margin: [10, 5],
231
+ * })
232
+ * ```
233
+ */
234
+ margin?: number | [number, number]
235
+ /**
236
+ * Whether to register hits inside of shapes (beyond the margin), such as the inside of a solid shape.
237
+ */
238
+ hitInside?: boolean
239
+ /**
240
+ * Whether to register hits on locked shapes.
241
+ */
242
+ hitLocked?: boolean
243
+ /**
244
+ * Whether to register hits on labels.
245
+ */
246
+ hitLabels?: boolean
247
+ /**
248
+ * Whether to only return hits on shapes that are currently being rendered.
249
+ * todo: rename this to hitCulled or hitNotRendering
250
+ */
251
+ renderingOnly?: boolean
252
+ /**
253
+ * Whether to register hits on the inside of frame shapes.
254
+ * todo: rename this to hitInsideFrames
255
+ */
256
+ hitFrameInside?: boolean
257
+ /**
258
+ * A filter function to apply to the shapes.
259
+ */
260
+ filter?(shape: TLShape): boolean
261
+ }
@@ -1,5 +1,5 @@
1
1
  import { useValue } from '@tldraw/state-react'
2
- import React, { useEffect, useMemo } from 'react'
2
+ import React, { useMemo } from 'react'
3
3
  import { RIGHT_MOUSE_BUTTON } from '../constants'
4
4
  import {
5
5
  preventDefault,
@@ -16,6 +16,9 @@ export function useCanvasEvents() {
16
16
 
17
17
  const events = useMemo(
18
18
  function canvasEvents() {
19
+ // Track the last screen point
20
+ let lastX: number, lastY: number
21
+
19
22
  function onPointerDown(e: React.PointerEvent) {
20
23
  if ((e as any).isKilled) return
21
24
 
@@ -41,9 +44,35 @@ export function useCanvasEvents() {
41
44
  })
42
45
  }
43
46
 
47
+ function onPointerMove(e: React.PointerEvent) {
48
+ if ((e as any).isKilled) return
49
+
50
+ if (e.clientX === lastX && e.clientY === lastY) return
51
+ lastX = e.clientX
52
+ lastY = e.clientY
53
+
54
+ // For tools that benefit from a higher fidelity of events,
55
+ // we dispatch the coalesced events.
56
+ // N.B. Sometimes getCoalescedEvents isn't present on iOS, ugh.
57
+ const events =
58
+ currentTool.useCoalescedEvents && e.nativeEvent.getCoalescedEvents
59
+ ? e.nativeEvent.getCoalescedEvents()
60
+ : [e]
61
+ for (const singleEvent of events) {
62
+ editor.dispatch({
63
+ type: 'pointer',
64
+ target: 'canvas',
65
+ name: 'pointer_move',
66
+ ...getPointerInfo(singleEvent),
67
+ })
68
+ }
69
+ }
70
+
44
71
  function onPointerUp(e: React.PointerEvent) {
45
72
  if ((e as any).isKilled) return
46
73
  if (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return
74
+ lastX = e.clientX
75
+ lastY = e.clientY
47
76
 
48
77
  releasePointerCapture(e.currentTarget, e)
49
78
 
@@ -129,6 +158,7 @@ export function useCanvasEvents() {
129
158
 
130
159
  return {
131
160
  onPointerDown,
161
+ onPointerMove,
132
162
  onPointerUp,
133
163
  onPointerEnter,
134
164
  onPointerLeave,
@@ -139,45 +169,8 @@ export function useCanvasEvents() {
139
169
  onClick,
140
170
  }
141
171
  },
142
- [editor]
172
+ [editor, currentTool]
143
173
  )
144
174
 
145
- // onPointerMove is special: where we're only interested in the other events when they're
146
- // happening _on_ the canvas (as opposed to outside of it, or on UI floating over it), we want
147
- // the pointer position to be up to date regardless of whether it's over the tldraw canvas or
148
- // not. So instead of returning a listener to be attached to the canvas, we directly attach a
149
- // listener to the whole document instead.
150
- useEffect(() => {
151
- let lastX: number, lastY: number
152
-
153
- function onPointerMove(e: PointerEvent) {
154
- if ((e as any).isKilled) return
155
- ;(e as any).isKilled = true
156
-
157
- if (e.clientX === lastX && e.clientY === lastY) return
158
- lastX = e.clientX
159
- lastY = e.clientY
160
-
161
- // For tools that benefit from a higher fidelity of events,
162
- // we dispatch the coalesced events.
163
- // N.B. Sometimes getCoalescedEvents isn't present on iOS, ugh.
164
- const events =
165
- currentTool.useCoalescedEvents && e.getCoalescedEvents ? e.getCoalescedEvents() : [e]
166
- for (const singleEvent of events) {
167
- editor.dispatch({
168
- type: 'pointer',
169
- target: 'canvas',
170
- name: 'pointer_move',
171
- ...getPointerInfo(singleEvent),
172
- })
173
- }
174
- }
175
-
176
- document.body.addEventListener('pointermove', onPointerMove)
177
- return () => {
178
- document.body.removeEventListener('pointermove', onPointerMove)
179
- }
180
- }, [editor, currentTool])
181
-
182
175
  return events
183
176
  }
@@ -53,6 +53,7 @@ export interface TldrawOptions {
53
53
  readonly flattenImageBoundsPadding: number
54
54
  readonly laserDelayMs: number
55
55
  readonly maxExportDelayMs: number
56
+ readonly tooltipDelayMs: number
56
57
  /**
57
58
  * How long should previews created by {@link Editor.createTemporaryAssetPreview} last before
58
59
  * they expire? Defaults to 3 minutes.
@@ -124,6 +125,7 @@ export const defaultTldrawOptions = {
124
125
  flattenImageBoundsPadding: 16,
125
126
  laserDelayMs: 1200,
126
127
  maxExportDelayMs: 5000,
128
+ tooltipDelayMs: 700,
127
129
  temporaryAssetPreviewLifetimeMs: 180000,
128
130
  actionShortcutsLocation: 'swap',
129
131
  createTextOnCanvasDoubleClick: true,
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.16.0-canary.8c74738e06fb'
4
+ export const version = '3.16.0-canary.a03de714c746'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2025-08-06T08:29:26.797Z',
8
- patch: '2025-08-06T08:29:26.797Z',
7
+ minor: '2025-08-06T14:07:34.822Z',
8
+ patch: '2025-08-06T14:07:34.822Z',
9
9
  }