@tldraw/editor 3.15.0 → 3.16.0-canary.03ed24d72068

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 (105) hide show
  1. package/dist-cjs/index.d.ts +181 -9
  2. package/dist-cjs/index.js +5 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +3 -1
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/MenuClickCapture.js +0 -5
  7. package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
  8. package/dist-cjs/lib/components/Shape.js +4 -26
  9. package/dist-cjs/lib/components/Shape.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
  11. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +1 -1
  12. package/dist-cjs/lib/components/default-components/DefaultScribble.js +1 -1
  13. package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
  14. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +9 -1
  15. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  16. package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js +53 -0
  17. package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js.map +7 -0
  18. package/dist-cjs/lib/config/TLUserPreferences.js +8 -2
  19. package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
  20. package/dist-cjs/lib/editor/Editor.js +100 -58
  21. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  22. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +8 -3
  23. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  24. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  25. package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
  26. package/dist-cjs/lib/exports/getSvgJsx.js +1 -2
  27. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  28. package/dist-cjs/lib/hooks/useCanvasEvents.js +24 -20
  29. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  30. package/dist-cjs/lib/hooks/useEditorComponents.js +2 -0
  31. package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
  32. package/dist-cjs/lib/hooks/useStateAttribute.js +35 -0
  33. package/dist-cjs/lib/hooks/useStateAttribute.js.map +7 -0
  34. package/dist-cjs/lib/license/Watermark.js +6 -6
  35. package/dist-cjs/lib/license/Watermark.js.map +1 -1
  36. package/dist-cjs/lib/options.js +1 -0
  37. package/dist-cjs/lib/options.js.map +2 -2
  38. package/dist-cjs/lib/utils/EditorAtom.js +45 -0
  39. package/dist-cjs/lib/utils/EditorAtom.js.map +7 -0
  40. package/dist-cjs/version.js +3 -3
  41. package/dist-cjs/version.js.map +1 -1
  42. package/dist-esm/index.d.mts +181 -9
  43. package/dist-esm/index.mjs +7 -1
  44. package/dist-esm/index.mjs.map +2 -2
  45. package/dist-esm/lib/TldrawEditor.mjs +3 -1
  46. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  47. package/dist-esm/lib/components/MenuClickCapture.mjs +0 -5
  48. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  49. package/dist-esm/lib/components/Shape.mjs +4 -26
  50. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  51. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
  52. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +1 -1
  53. package/dist-esm/lib/components/default-components/DefaultScribble.mjs +1 -1
  54. package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
  55. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +9 -1
  56. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  57. package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs +23 -0
  58. package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs.map +7 -0
  59. package/dist-esm/lib/config/TLUserPreferences.mjs +8 -2
  60. package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
  61. package/dist-esm/lib/editor/Editor.mjs +100 -58
  62. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  63. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +8 -3
  64. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  65. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  66. package/dist-esm/lib/exports/getSvgJsx.mjs +2 -2
  67. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  68. package/dist-esm/lib/hooks/useCanvasEvents.mjs +25 -21
  69. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  70. package/dist-esm/lib/hooks/useEditorComponents.mjs +4 -0
  71. package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
  72. package/dist-esm/lib/hooks/useStateAttribute.mjs +15 -0
  73. package/dist-esm/lib/hooks/useStateAttribute.mjs.map +7 -0
  74. package/dist-esm/lib/license/Watermark.mjs +6 -6
  75. package/dist-esm/lib/license/Watermark.mjs.map +1 -1
  76. package/dist-esm/lib/options.mjs +1 -0
  77. package/dist-esm/lib/options.mjs.map +2 -2
  78. package/dist-esm/lib/utils/EditorAtom.mjs +25 -0
  79. package/dist-esm/lib/utils/EditorAtom.mjs.map +7 -0
  80. package/dist-esm/version.mjs +3 -3
  81. package/dist-esm/version.mjs.map +1 -1
  82. package/editor.css +297 -311
  83. package/package.json +7 -7
  84. package/src/index.ts +7 -0
  85. package/src/lib/TldrawEditor.tsx +7 -5
  86. package/src/lib/components/MenuClickCapture.tsx +0 -8
  87. package/src/lib/components/Shape.tsx +6 -21
  88. package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
  89. package/src/lib/components/default-components/DefaultScribble.tsx +1 -1
  90. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +5 -1
  91. package/src/lib/components/default-components/DefaultShapeWrapper.tsx +35 -0
  92. package/src/lib/config/TLUserPreferences.ts +7 -0
  93. package/src/lib/editor/Editor.ts +130 -81
  94. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +13 -0
  95. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +5 -0
  96. package/src/lib/editor/shapes/ShapeUtil.ts +57 -0
  97. package/src/lib/editor/types/misc-types.ts +73 -1
  98. package/src/lib/exports/getSvgJsx.tsx +2 -2
  99. package/src/lib/hooks/useCanvasEvents.ts +39 -32
  100. package/src/lib/hooks/useEditorComponents.tsx +7 -1
  101. package/src/lib/hooks/useStateAttribute.ts +15 -0
  102. package/src/lib/license/Watermark.tsx +6 -6
  103. package/src/lib/options.ts +2 -0
  104. package/src/lib/utils/EditorAtom.ts +37 -0
  105. package/src/version.ts +3 -3
@@ -584,6 +584,15 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
584
584
  */
585
585
  onResizeEnd?(initial: Shape, current: Shape): TLShapePartial<Shape> | void
586
586
 
587
+ /**
588
+ * A callback called when a shape resize is cancelled.
589
+ *
590
+ * @param initial - The shape at the start of the resize.
591
+ * @param current - The current shape.
592
+ * @public
593
+ */
594
+ onResizeCancel?(initial: Shape, current: Shape): void
595
+
587
596
  /**
588
597
  * A callback called when a shape starts being translated.
589
598
  *
@@ -613,6 +622,25 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
613
622
  */
614
623
  onTranslateEnd?(initial: Shape, current: Shape): TLShapePartial<Shape> | void
615
624
 
625
+ /**
626
+ * A callback called when a shape translation is cancelled.
627
+ *
628
+ * @param initial - The shape at the start of the translation.
629
+ * @param current - The current shape.
630
+ * @public
631
+ */
632
+ onTranslateCancel?(initial: Shape, current: Shape): void
633
+
634
+ /**
635
+ * A callback called when a shape's handle starts being dragged.
636
+ *
637
+ * @param shape - The shape.
638
+ * @param info - An object containing the handle and whether the handle is 'precise' or not.
639
+ * @returns A change to apply to the shape, or void.
640
+ * @public
641
+ */
642
+ onHandleDragStart?(shape: Shape, info: TLHandleDragInfo<Shape>): TLShapePartial<Shape> | void
643
+
616
644
  /**
617
645
  * A callback called when a shape's handle changes.
618
646
  *
@@ -623,6 +651,25 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
623
651
  */
624
652
  onHandleDrag?(shape: Shape, info: TLHandleDragInfo<Shape>): TLShapePartial<Shape> | void
625
653
 
654
+ /**
655
+ * A callback called when a shape's handle finishes being dragged.
656
+ *
657
+ * @param current - The current shape.
658
+ * @param info - An object containing the handle and whether the handle is 'precise' or not.
659
+ * @returns A change to apply to the shape, or void.
660
+ * @public
661
+ */
662
+ onHandleDragEnd?(current: Shape, info: TLHandleDragInfo<Shape>): TLShapePartial<Shape> | void
663
+
664
+ /**
665
+ * A callback called when a shape's handle drag is cancelled.
666
+ *
667
+ * @param current - The current shape.
668
+ * @param info - An object containing the handle and whether the handle is 'precise' or not.
669
+ * @public
670
+ */
671
+ onHandleDragCancel?(current: Shape, info: TLHandleDragInfo<Shape>): void
672
+
626
673
  /**
627
674
  * A callback called when a shape starts being rotated.
628
675
  *
@@ -652,6 +699,15 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
652
699
  */
653
700
  onRotateEnd?(initial: Shape, current: Shape): TLShapePartial<Shape> | void
654
701
 
702
+ /**
703
+ * A callback called when a shape rotation is cancelled.
704
+ *
705
+ * @param initial - The shape at the start of the rotation.
706
+ * @param current - The current shape.
707
+ * @public
708
+ */
709
+ onRotateCancel?(initial: Shape, current: Shape): void
710
+
655
711
  /**
656
712
  * Not currently used.
657
713
  *
@@ -819,5 +875,6 @@ export interface TLResizeInfo<T extends TLShape> {
819
875
  export interface TLHandleDragInfo<T extends TLShape> {
820
876
  handle: TLHandle
821
877
  isPrecise: boolean
878
+ isCreatingShape: boolean
822
879
  initial?: T | undefined
823
880
  }
@@ -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
 
@@ -187,3 +187,75 @@ export interface TLCameraConstraints {
187
187
  y: 'free' | 'fixed' | 'inside' | 'outside' | 'contain'
188
188
  }
189
189
  }
190
+
191
+ /** @public */
192
+ export interface TLUpdatePointerOptions {
193
+ /** Whether to update the pointer immediately, rather than on the next tick. */
194
+ immediate?: boolean
195
+ /**
196
+ * The point, in screen-space, to update the pointer to. Defaults to the position of the last
197
+ * pointer event.
198
+ */
199
+ point?: VecLike
200
+ pointerId?: number
201
+ ctrlKey?: boolean
202
+ altKey?: boolean
203
+ shiftKey?: boolean
204
+ metaKey?: boolean
205
+ accelKey?: boolean
206
+ isPen?: boolean
207
+ button?: number
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
+ }
@@ -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
  }
@@ -1,4 +1,4 @@
1
- import { ComponentType, ReactNode, createContext, useContext, useMemo } from 'react'
1
+ import { ComponentType, ReactNode, RefAttributes, createContext, useContext, useMemo } from 'react'
2
2
  import { DefaultBackground } from '../components/default-components/DefaultBackground'
3
3
  import { DefaultBrush, TLBrushProps } from '../components/default-components/DefaultBrush'
4
4
  import {
@@ -37,6 +37,10 @@ import {
37
37
  TLShapeIndicatorErrorFallbackComponent,
38
38
  } from '../components/default-components/DefaultShapeIndicatorErrorFallback'
39
39
  import { DefaultShapeIndicators } from '../components/default-components/DefaultShapeIndicators'
40
+ import {
41
+ DefaultShapeWrapper,
42
+ TLShapeWrapperProps,
43
+ } from '../components/default-components/DefaultShapeWrapper'
40
44
  import {
41
45
  DefaultSnapIndicator,
42
46
  TLSnapIndicatorProps,
@@ -68,6 +72,7 @@ export interface TLEditorComponents {
68
72
  SelectionForeground?: ComponentType<TLSelectionForegroundProps> | null
69
73
  ShapeIndicator?: ComponentType<TLShapeIndicatorProps> | null
70
74
  ShapeIndicators?: ComponentType | null
75
+ ShapeWrapper?: ComponentType<TLShapeWrapperProps & RefAttributes<HTMLDivElement>> | null
71
76
  SnapIndicator?: ComponentType<TLSnapIndicatorProps> | null
72
77
  Spinner?: ComponentType<React.SVGProps<SVGSVGElement>> | null
73
78
  SvgDefs?: ComponentType | null
@@ -114,6 +119,7 @@ export function EditorComponentsProvider({
114
119
  SelectionForeground: DefaultSelectionForeground,
115
120
  ShapeIndicator: DefaultShapeIndicator,
116
121
  ShapeIndicators: DefaultShapeIndicators,
122
+ ShapeWrapper: DefaultShapeWrapper,
117
123
  SnapIndicator: DefaultSnapIndicator,
118
124
  Spinner: DefaultSpinner,
119
125
  SvgDefs: DefaultSvgDefs,
@@ -0,0 +1,15 @@
1
+ import { react } from '@tldraw/state'
2
+ import { useLayoutEffect } from 'react'
3
+ import { useEditor } from './useEditor'
4
+
5
+ export function useStateAttribute() {
6
+ const editor = useEditor()
7
+
8
+ // we use a layout effect because we don't want there to be any perceptible delay between the
9
+ // editor mounting and this attribute being applied, because styles may depend on it:
10
+ useLayoutEffect(() => {
11
+ return react('stateAttribute', () => {
12
+ editor.getContainer().setAttribute('data-state', editor.getPath())
13
+ })
14
+ }, [editor])
15
+ }
@@ -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
  }
@@ -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,
@@ -0,0 +1,37 @@
1
+ import { atom, Atom } from '@tldraw/state'
2
+ import { WeakCache } from '@tldraw/utils'
3
+ import { Editor } from '../editor/Editor'
4
+
5
+ /**
6
+ * An Atom that is scoped to the lifetime of an Editor.
7
+ *
8
+ * This is useful for storing UI state for tldraw applications. Keeping state scoped to an editor
9
+ * instead of stored in a global atom can prevent issues with state being shared between editors
10
+ * when navigating between pages, or when multiple editor instances are used on the same page.
11
+ *
12
+ * @public
13
+ */
14
+ export class EditorAtom<T> {
15
+ private states = new WeakCache<Editor, Atom<T>>()
16
+
17
+ constructor(
18
+ private name: string,
19
+ private getInitialState: (editor: Editor) => T
20
+ ) {}
21
+
22
+ getAtom(editor: Editor): Atom<T> {
23
+ return this.states.get(editor, () => atom(this.name, this.getInitialState(editor)))
24
+ }
25
+
26
+ get(editor: Editor): T {
27
+ return this.getAtom(editor).get()
28
+ }
29
+
30
+ update(editor: Editor, update: (state: T) => T): T {
31
+ return this.getAtom(editor).update(update)
32
+ }
33
+
34
+ set(editor: Editor, state: T): T {
35
+ return this.getAtom(editor).set(state)
36
+ }
37
+ }
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.15.0'
4
+ export const version = '3.16.0-canary.03ed24d72068'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2025-07-30T09:07:27.887Z',
8
- patch: '2025-07-30T09:07:27.887Z',
7
+ minor: '2025-08-13T15:17:41.559Z',
8
+ patch: '2025-08-13T15:17:41.559Z',
9
9
  }