@tldraw/editor 3.16.0-canary.a962044c3d3b → 3.16.0-canary.acb40a76700b

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 (54) hide show
  1. package/dist-cjs/index.js +1 -1
  2. package/dist-cjs/lib/TldrawEditor.js +1 -1
  3. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  4. package/dist-cjs/lib/components/MenuClickCapture.js +0 -5
  5. package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
  6. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
  7. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +1 -1
  8. package/dist-cjs/lib/components/default-components/DefaultScribble.js +1 -1
  9. package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +9 -1
  11. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  12. package/dist-cjs/lib/editor/Editor.js +17 -14
  13. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  14. package/dist-cjs/lib/exports/getSvgJsx.js +1 -2
  15. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  16. package/dist-cjs/lib/hooks/useCanvasEvents.js +24 -20
  17. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  18. package/dist-cjs/lib/license/Watermark.js +6 -6
  19. package/dist-cjs/lib/license/Watermark.js.map +1 -1
  20. package/dist-cjs/version.js +3 -3
  21. package/dist-cjs/version.js.map +1 -1
  22. package/dist-esm/index.mjs +1 -1
  23. package/dist-esm/lib/TldrawEditor.mjs +1 -1
  24. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  25. package/dist-esm/lib/components/MenuClickCapture.mjs +0 -5
  26. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  27. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
  28. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +1 -1
  29. package/dist-esm/lib/components/default-components/DefaultScribble.mjs +1 -1
  30. package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
  31. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +9 -1
  32. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  33. package/dist-esm/lib/editor/Editor.mjs +17 -14
  34. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  35. package/dist-esm/lib/exports/getSvgJsx.mjs +2 -2
  36. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  37. package/dist-esm/lib/hooks/useCanvasEvents.mjs +25 -21
  38. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  39. package/dist-esm/lib/license/Watermark.mjs +6 -6
  40. package/dist-esm/lib/license/Watermark.mjs.map +1 -1
  41. package/dist-esm/version.mjs +3 -3
  42. package/dist-esm/version.mjs.map +1 -1
  43. package/editor.css +293 -290
  44. package/package.json +7 -7
  45. package/src/lib/TldrawEditor.tsx +5 -5
  46. package/src/lib/components/MenuClickCapture.tsx +0 -8
  47. package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
  48. package/src/lib/components/default-components/DefaultScribble.tsx +1 -1
  49. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +5 -1
  50. package/src/lib/editor/Editor.ts +26 -19
  51. package/src/lib/exports/getSvgJsx.tsx +2 -2
  52. package/src/lib/hooks/useCanvasEvents.ts +39 -32
  53. package/src/lib/license/Watermark.tsx +6 -6
  54. package/src/version.ts +3 -3
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tldraw/editor",
3
3
  "description": "tldraw infinite canvas SDK (editor).",
4
- "version": "3.16.0-canary.a962044c3d3b",
4
+ "version": "3.16.0-canary.acb40a76700b",
5
5
  "author": {
6
6
  "name": "tldraw Inc.",
7
7
  "email": "hello@tldraw.com"
@@ -49,12 +49,12 @@
49
49
  "@tiptap/core": "^2.9.1",
50
50
  "@tiptap/pm": "^2.9.1",
51
51
  "@tiptap/react": "^2.9.1",
52
- "@tldraw/state": "3.16.0-canary.a962044c3d3b",
53
- "@tldraw/state-react": "3.16.0-canary.a962044c3d3b",
54
- "@tldraw/store": "3.16.0-canary.a962044c3d3b",
55
- "@tldraw/tlschema": "3.16.0-canary.a962044c3d3b",
56
- "@tldraw/utils": "3.16.0-canary.a962044c3d3b",
57
- "@tldraw/validate": "3.16.0-canary.a962044c3d3b",
52
+ "@tldraw/state": "3.16.0-canary.acb40a76700b",
53
+ "@tldraw/state-react": "3.16.0-canary.acb40a76700b",
54
+ "@tldraw/store": "3.16.0-canary.acb40a76700b",
55
+ "@tldraw/tlschema": "3.16.0-canary.acb40a76700b",
56
+ "@tldraw/utils": "3.16.0-canary.acb40a76700b",
57
+ "@tldraw/validate": "3.16.0-canary.acb40a76700b",
58
58
  "@types/core-js": "^2.5.8",
59
59
  "@use-gesture/react": "^10.3.1",
60
60
  "classnames": "^2.5.1",
@@ -1,9 +1,9 @@
1
1
  import { MigrationSequence, Store } from '@tldraw/store'
2
2
  import { TLShape, TLStore, TLStoreSnapshot } from '@tldraw/tlschema'
3
- import { Required, annotateError } from '@tldraw/utils'
3
+ import { annotateError, Required } from '@tldraw/utils'
4
4
  import React, {
5
- ReactNode,
6
5
  memo,
6
+ ReactNode,
7
7
  useCallback,
8
8
  useEffect,
9
9
  useLayoutEffect,
@@ -15,13 +15,13 @@ import React, {
15
15
 
16
16
  import classNames from 'classnames'
17
17
  import { version } from '../version'
18
- import { OptionalErrorBoundary } from './components/ErrorBoundary'
19
18
  import { DefaultErrorFallback } from './components/default-components/DefaultErrorFallback'
20
- import { TLEditorSnapshot } from './config/TLEditorSnapshot'
19
+ import { OptionalErrorBoundary } from './components/ErrorBoundary'
21
20
  import { TLStoreBaseOptions } from './config/createTLStore'
22
- import { TLUser, createTLUser } from './config/createTLUser'
21
+ import { createTLUser, TLUser } from './config/createTLUser'
23
22
  import { TLAnyBindingUtilConstructor } from './config/defaultBindings'
24
23
  import { TLAnyShapeUtilConstructor } from './config/defaultShapes'
24
+ import { TLEditorSnapshot } from './config/TLEditorSnapshot'
25
25
  import { Editor } from './editor/Editor'
26
26
  import { TLStateNodeConstructor } from './editor/tools/StateNode'
27
27
  import { TLCameraOptions } from './editor/types/misc-types'
@@ -50,12 +50,6 @@ export function MenuClickCapture() {
50
50
  // Do nothing unless we're pointing
51
51
  if (!rPointerState.current.isDown) return
52
52
 
53
- // If we're already dragging, pass on the event as it is
54
- if (rPointerState.current.isDragging) {
55
- canvasEvents.onPointerMove?.(e)
56
- return
57
- }
58
-
59
53
  if (
60
54
  // We're pointing, but are we dragging?
61
55
  Vec.Dist2(rPointerState.current.start, new Vec(e.clientX, e.clientY)) >
@@ -75,8 +69,6 @@ export function MenuClickCapture() {
75
69
  clientY: y,
76
70
  button: 0,
77
71
  })
78
- // call the pointer move with the current pointer position
79
- canvasEvents.onPointerMove?.(e)
80
72
  }
81
73
  },
82
74
  [canvasEvents, editor]
@@ -44,7 +44,7 @@ export function DefaultCollaboratorHint({
44
44
  href={`#${cursorHintId}`}
45
45
  color={color}
46
46
  strokeWidth={3}
47
- stroke="var(--color-background)"
47
+ stroke="var(--tl-color-background)"
48
48
  />
49
49
  <use href={`#${cursorHintId}`} color={color} opacity={opacity} />
50
50
  </svg>
@@ -21,7 +21,7 @@ export function DefaultScribble({ scribble, zoom, color, opacity, className }: T
21
21
  <path
22
22
  className="tl-scribble"
23
23
  d={getSvgPathFromPoints(scribble.points, false)}
24
- stroke={color ?? `var(--color-${scribble.color})`}
24
+ stroke={color ?? `var(--tl-color-${scribble.color})`}
25
25
  fill="none"
26
26
  strokeWidth={8 / zoom}
27
27
  opacity={opacity ?? scribble.opacity}
@@ -87,7 +87,11 @@ export const DefaultShapeIndicator = memo(function DefaultShapeIndicator({
87
87
 
88
88
  return (
89
89
  <svg ref={rIndicator} className={classNames('tl-overlays__item', className)} aria-hidden="true">
90
- <g className="tl-shape-indicator" stroke={color ?? 'var(--color-selected)'} opacity={opacity}>
90
+ <g
91
+ className="tl-shape-indicator"
92
+ stroke={color ?? 'var(--tl-color-selected)'}
93
+ opacity={opacity}
94
+ >
91
95
  <InnerIndicator editor={editor} id={shapeId} />
92
96
  </g>
93
97
  </svg>
@@ -7857,25 +7857,32 @@ export class Editor extends EventEmitter<TLEventMap> {
7857
7857
  ) {
7858
7858
  let parentId: TLParentId = this.getFocusedGroupId()
7859
7859
 
7860
- for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
7861
- const parent = currentPageShapesSorted[i]
7862
- const util = this.getShapeUtil(parent)
7863
- if (
7864
- util.canReceiveNewChildrenOfType(parent, partial.type) &&
7865
- !this.isShapeHidden(parent) &&
7866
- this.isPointInShape(
7867
- parent,
7868
- // If no parent is provided, then we can treat the
7869
- // shape's provided x/y as being in the page's space.
7870
- { x: partial.x ?? 0, y: partial.y ?? 0 },
7871
- {
7872
- margin: 0,
7873
- hitInside: true,
7874
- }
7875
- )
7876
- ) {
7877
- parentId = parent.id
7878
- break
7860
+ const isPositioned = partial.x !== undefined && partial.y !== undefined
7861
+
7862
+ // If the shape has been explicitly positioned, we'll try to find a parent at
7863
+ // that position. If not, we'll assume the user isn't deliberately placing the
7864
+ // shape and the positioning will be handled later by another system.
7865
+ if (isPositioned) {
7866
+ for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
7867
+ const parent = currentPageShapesSorted[i]
7868
+ const util = this.getShapeUtil(parent)
7869
+ if (
7870
+ util.canReceiveNewChildrenOfType(parent, partial.type) &&
7871
+ !this.isShapeHidden(parent) &&
7872
+ this.isPointInShape(
7873
+ parent,
7874
+ // If no parent is provided, then we can treat the
7875
+ // shape's provided x/y as being in the page's space.
7876
+ { x: partial.x ?? 0, y: partial.y ?? 0 },
7877
+ {
7878
+ margin: 0,
7879
+ hitInside: true,
7880
+ }
7881
+ )
7882
+ ) {
7883
+ parentId = parent.id
7884
+ break
7885
+ }
7879
7886
  }
7880
7887
  }
7881
7888
 
@@ -4,6 +4,7 @@ import {
4
4
  TLGroupShape,
5
5
  TLShape,
6
6
  TLShapeId,
7
+ getColorValue,
7
8
  getDefaultColorTheme,
8
9
  } from '@tldraw/tlschema'
9
10
  import { hasOwnProperty, promiseWithResolve, uniqueId } from '@tldraw/utils'
@@ -373,8 +374,7 @@ function SvgExport({
373
374
  | { options: { showColors: boolean } }
374
375
  if (frameShapeUtil?.options.showColors) {
375
376
  const shape = editor.getShape(singleFrameShapeId)! as TLFrameShape
376
- const color = theme[shape.props.color]
377
- backgroundColor = color.frame.fill
377
+ backgroundColor = getColorValue(theme, shape.props.color, 'frameFill')
378
378
  } else {
379
379
  backgroundColor = theme.solid
380
380
  }
@@ -1,5 +1,5 @@
1
1
  import { useValue } from '@tldraw/state-react'
2
- import React, { useMemo } from 'react'
2
+ import React, { useEffect, useMemo } from 'react'
3
3
  import { RIGHT_MOUSE_BUTTON } from '../constants'
4
4
  import {
5
5
  preventDefault,
@@ -16,9 +16,6 @@ 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
-
22
19
  function onPointerDown(e: React.PointerEvent) {
23
20
  if ((e as any).isKilled) return
24
21
 
@@ -44,35 +41,9 @@ export function useCanvasEvents() {
44
41
  })
45
42
  }
46
43
 
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
-
71
44
  function onPointerUp(e: React.PointerEvent) {
72
45
  if ((e as any).isKilled) return
73
46
  if (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return
74
- lastX = e.clientX
75
- lastY = e.clientY
76
47
 
77
48
  releasePointerCapture(e.currentTarget, e)
78
49
 
@@ -158,7 +129,6 @@ export function useCanvasEvents() {
158
129
 
159
130
  return {
160
131
  onPointerDown,
161
- onPointerMove,
162
132
  onPointerUp,
163
133
  onPointerEnter,
164
134
  onPointerLeave,
@@ -169,8 +139,45 @@ export function useCanvasEvents() {
169
139
  onClick,
170
140
  }
171
141
  },
172
- [editor, currentTool]
142
+ [editor]
173
143
  )
174
144
 
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
+
175
182
  return events
176
183
  }
@@ -86,15 +86,15 @@ To remove the watermark, please purchase a license at tldraw.dev.
86
86
 
87
87
  .${className} {
88
88
  position: absolute;
89
- bottom: var(--space-2);
90
- right: var(--space-2);
89
+ bottom: var(--tl-space-2);
90
+ right: var(--tl-space-2);
91
91
  width: 96px;
92
92
  height: 32px;
93
93
  display: flex;
94
94
  align-items: center;
95
95
  justify-content: center;
96
- z-index: var(--layer-watermark) !important;
97
- background-color: color-mix(in srgb, var(--color-background) 62%, transparent);
96
+ z-index: var(--tl-layer-watermark) !important;
97
+ background-color: color-mix(in srgb, var(--tl-color-background) 62%, transparent);
98
98
  opacity: 1;
99
99
  border-radius: 5px;
100
100
  pointer-events: all;
@@ -108,7 +108,7 @@ To remove the watermark, please purchase a license at tldraw.dev.
108
108
  height: 32px;
109
109
  pointer-events: all;
110
110
  cursor: inherit;
111
- color: var(--color-text);
111
+ color: var(--tl-color-text);
112
112
  opacity: .38;
113
113
  border: 0;
114
114
  padding: 0;
@@ -137,7 +137,7 @@ To remove the watermark, please purchase a license at tldraw.dev.
137
137
  }
138
138
 
139
139
  .${className}:hover {
140
- background-color: var(--color-background);
140
+ background-color: var(--tl-color-background);
141
141
  transition: background-color 0.2s ease-in-out;
142
142
  transition-delay: 0.32s;
143
143
  }
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.a962044c3d3b'
4
+ export const version = '3.16.0-canary.acb40a76700b'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2025-08-08T12:11:20.287Z',
8
- patch: '2025-08-08T12:11:20.287Z',
7
+ minor: '2025-08-14T14:04:21.487Z',
8
+ patch: '2025-08-14T14:04:21.487Z',
9
9
  }