@tldraw/editor 4.6.0-internal.e29318c66fb0 → 4.6.0-next.0a51207761bb

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 (270) hide show
  1. package/dist-cjs/index.d.ts +850 -118
  2. package/dist-cjs/index.js +20 -6
  3. package/dist-cjs/index.js.map +3 -3
  4. package/dist-cjs/lib/TldrawEditor.js +59 -14
  5. package/dist-cjs/lib/TldrawEditor.js.map +3 -3
  6. package/dist-cjs/lib/components/MenuClickCapture.js +16 -1
  7. package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
  8. package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js +3 -3
  9. package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -1
  11. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  12. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
  13. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +2 -2
  14. package/dist-cjs/lib/config/{createTLUser.js → createTLCurrentUser.js} +9 -9
  15. package/dist-cjs/lib/config/createTLCurrentUser.js.map +7 -0
  16. package/dist-cjs/lib/config/createTLStore.js +31 -1
  17. package/dist-cjs/lib/config/createTLStore.js.map +2 -2
  18. package/dist-cjs/lib/config/defaultAssets.js +36 -0
  19. package/dist-cjs/lib/config/defaultAssets.js.map +7 -0
  20. package/dist-cjs/lib/config/defaultShapes.js.map +2 -2
  21. package/dist-cjs/lib/editor/Editor.js +329 -12
  22. package/dist-cjs/lib/editor/Editor.js.map +3 -3
  23. package/dist-cjs/lib/editor/assets/AssetUtil.js +66 -0
  24. package/dist-cjs/lib/editor/assets/AssetUtil.js.map +7 -0
  25. package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +1 -1
  26. package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
  27. package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
  28. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.js +80 -0
  29. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.js.map +7 -0
  30. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js +466 -0
  31. package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js.map +7 -0
  32. package/dist-cjs/lib/editor/managers/PerformanceManager/perf-types.js +17 -0
  33. package/dist-cjs/lib/editor/managers/PerformanceManager/perf-types.js.map +7 -0
  34. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +1 -1
  35. package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
  36. package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +2 -2
  37. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +4 -4
  38. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +2 -2
  39. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +102 -30
  40. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  41. package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js +106 -0
  42. package/dist-cjs/lib/editor/managers/ThemeManager/ThemeManager.js.map +7 -0
  43. package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js +586 -0
  44. package/dist-cjs/lib/editor/managers/ThemeManager/defaultThemes.js.map +7 -0
  45. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +6 -4
  46. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  47. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +21 -2
  48. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  49. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +1 -1
  50. package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
  51. package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js +6 -0
  52. package/dist-cjs/lib/editor/shapes/shared/getPerfectDashProps.js.map +2 -2
  53. package/dist-cjs/lib/editor/tools/StateNode.js +14 -17
  54. package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
  55. package/dist-cjs/lib/editor/types/SvgExportContext.js.map +2 -2
  56. package/dist-cjs/lib/editor/types/clipboard-types.js.map +1 -1
  57. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  58. package/dist-cjs/lib/exports/StyleEmbedder.js +1 -1
  59. package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
  60. package/dist-cjs/lib/exports/getSvgJsx.js +12 -7
  61. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  62. package/dist-cjs/lib/globals/environment.js +18 -1
  63. package/dist-cjs/lib/globals/environment.js.map +2 -2
  64. package/dist-cjs/lib/hooks/{useIsDarkMode.js → useColorMode.js} +14 -10
  65. package/dist-cjs/lib/hooks/useColorMode.js.map +7 -0
  66. package/dist-cjs/lib/hooks/useCursor.js +3 -7
  67. package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
  68. package/dist-cjs/lib/hooks/useDarkMode.js +4 -4
  69. package/dist-cjs/lib/hooks/useDarkMode.js.map +2 -2
  70. package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
  71. package/dist-cjs/lib/hooks/useGestureEvents.js +171 -127
  72. package/dist-cjs/lib/hooks/useGestureEvents.js.map +3 -3
  73. package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
  74. package/dist-cjs/lib/options.js +3 -0
  75. package/dist-cjs/lib/options.js.map +2 -2
  76. package/dist-cjs/lib/primitives/Box.js +1 -1
  77. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  78. package/dist-cjs/lib/primitives/geometry/Arc2d.js +2 -2
  79. package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
  80. package/dist-cjs/lib/primitives/geometry/Circle2d.js +2 -2
  81. package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +2 -2
  82. package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +2 -2
  83. package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +2 -2
  84. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +4 -3
  85. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  86. package/dist-cjs/lib/primitives/geometry/Polyline2d.js +1 -1
  87. package/dist-cjs/lib/primitives/geometry/Polyline2d.js.map +2 -2
  88. package/dist-cjs/lib/primitives/geometry/Stadium2d.js +1 -1
  89. package/dist-cjs/lib/primitives/geometry/Stadium2d.js.map +2 -2
  90. package/dist-cjs/lib/utils/getSvgPathFromPoints.js.map +2 -2
  91. package/dist-cjs/lib/utils/reparenting.js +2 -1
  92. package/dist-cjs/lib/utils/reparenting.js.map +2 -2
  93. package/dist-cjs/lib/utils/richText.js.map +2 -2
  94. package/dist-cjs/lib/utils/runtime.js +2 -1
  95. package/dist-cjs/lib/utils/runtime.js.map +2 -2
  96. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +1 -1
  97. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  98. package/dist-cjs/lib/utils/sync/hardReset.js +0 -8
  99. package/dist-cjs/lib/utils/sync/hardReset.js.map +2 -2
  100. package/dist-cjs/version.js +3 -3
  101. package/dist-cjs/version.js.map +1 -1
  102. package/dist-esm/index.d.mts +850 -118
  103. package/dist-esm/index.mjs +28 -10
  104. package/dist-esm/index.mjs.map +2 -2
  105. package/dist-esm/lib/TldrawEditor.mjs +62 -14
  106. package/dist-esm/lib/TldrawEditor.mjs.map +3 -3
  107. package/dist-esm/lib/components/MenuClickCapture.mjs +16 -1
  108. package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
  109. package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs +3 -3
  110. package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs.map +2 -2
  111. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +1 -1
  112. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  113. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
  114. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +2 -2
  115. package/dist-esm/lib/config/{createTLUser.mjs → createTLCurrentUser.mjs} +6 -6
  116. package/dist-esm/lib/config/createTLCurrentUser.mjs.map +7 -0
  117. package/dist-esm/lib/config/createTLStore.mjs +37 -2
  118. package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
  119. package/dist-esm/lib/config/defaultAssets.mjs +16 -0
  120. package/dist-esm/lib/config/defaultAssets.mjs.map +7 -0
  121. package/dist-esm/lib/config/defaultShapes.mjs.map +2 -2
  122. package/dist-esm/lib/editor/Editor.mjs +332 -13
  123. package/dist-esm/lib/editor/Editor.mjs.map +3 -3
  124. package/dist-esm/lib/editor/assets/AssetUtil.mjs +46 -0
  125. package/dist-esm/lib/editor/assets/AssetUtil.mjs.map +7 -0
  126. package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +1 -1
  127. package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
  128. package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
  129. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.mjs +60 -0
  130. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.mjs.map +7 -0
  131. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs +438 -0
  132. package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs.map +7 -0
  133. package/dist-esm/lib/editor/managers/PerformanceManager/perf-types.mjs +1 -0
  134. package/dist-esm/lib/editor/managers/PerformanceManager/perf-types.mjs.map +7 -0
  135. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +1 -1
  136. package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
  137. package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +2 -2
  138. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +4 -4
  139. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +2 -2
  140. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +102 -30
  141. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  142. package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs +88 -0
  143. package/dist-esm/lib/editor/managers/ThemeManager/ThemeManager.mjs.map +7 -0
  144. package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs +568 -0
  145. package/dist-esm/lib/editor/managers/ThemeManager/defaultThemes.mjs.map +7 -0
  146. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +6 -4
  147. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  148. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +21 -2
  149. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  150. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +1 -1
  151. package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
  152. package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs +6 -0
  153. package/dist-esm/lib/editor/shapes/shared/getPerfectDashProps.mjs.map +2 -2
  154. package/dist-esm/lib/editor/tools/StateNode.mjs +14 -17
  155. package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
  156. package/dist-esm/lib/editor/types/SvgExportContext.mjs.map +2 -2
  157. package/dist-esm/lib/exports/StyleEmbedder.mjs +1 -1
  158. package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
  159. package/dist-esm/lib/exports/getSvgJsx.mjs +12 -10
  160. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  161. package/dist-esm/lib/globals/environment.mjs +18 -1
  162. package/dist-esm/lib/globals/environment.mjs.map +2 -2
  163. package/dist-esm/lib/hooks/useColorMode.mjs +19 -0
  164. package/dist-esm/lib/hooks/useColorMode.mjs.map +7 -0
  165. package/dist-esm/lib/hooks/useCursor.mjs +3 -7
  166. package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
  167. package/dist-esm/lib/hooks/useDarkMode.mjs +4 -4
  168. package/dist-esm/lib/hooks/useDarkMode.mjs.map +2 -2
  169. package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
  170. package/dist-esm/lib/hooks/useGestureEvents.mjs +171 -127
  171. package/dist-esm/lib/hooks/useGestureEvents.mjs.map +3 -3
  172. package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
  173. package/dist-esm/lib/options.mjs +3 -0
  174. package/dist-esm/lib/options.mjs.map +2 -2
  175. package/dist-esm/lib/primitives/Box.mjs +1 -1
  176. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  177. package/dist-esm/lib/primitives/geometry/Arc2d.mjs +2 -2
  178. package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
  179. package/dist-esm/lib/primitives/geometry/Circle2d.mjs +2 -2
  180. package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +2 -2
  181. package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +2 -2
  182. package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +2 -2
  183. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +4 -3
  184. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  185. package/dist-esm/lib/primitives/geometry/Polyline2d.mjs +1 -1
  186. package/dist-esm/lib/primitives/geometry/Polyline2d.mjs.map +2 -2
  187. package/dist-esm/lib/primitives/geometry/Stadium2d.mjs +1 -1
  188. package/dist-esm/lib/primitives/geometry/Stadium2d.mjs.map +2 -2
  189. package/dist-esm/lib/utils/getSvgPathFromPoints.mjs.map +2 -2
  190. package/dist-esm/lib/utils/reparenting.mjs +2 -1
  191. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  192. package/dist-esm/lib/utils/richText.mjs.map +2 -2
  193. package/dist-esm/lib/utils/runtime.mjs +2 -1
  194. package/dist-esm/lib/utils/runtime.mjs.map +2 -2
  195. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +1 -1
  196. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  197. package/dist-esm/lib/utils/sync/hardReset.mjs +0 -8
  198. package/dist-esm/lib/utils/sync/hardReset.mjs.map +2 -2
  199. package/dist-esm/version.mjs +3 -3
  200. package/dist-esm/version.mjs.map +1 -1
  201. package/editor.css +13 -33
  202. package/package.json +8 -9
  203. package/src/index.ts +37 -8
  204. package/src/lib/TldrawEditor.tsx +99 -20
  205. package/src/lib/components/MenuClickCapture.tsx +20 -0
  206. package/src/lib/components/default-components/CanvasShapeIndicators.tsx +3 -3
  207. package/src/lib/components/default-components/DefaultCanvas.tsx +1 -1
  208. package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
  209. package/src/lib/config/TLEditorSnapshot.test.ts +1 -1
  210. package/src/lib/config/{createTLUser.ts → createTLCurrentUser.ts} +6 -6
  211. package/src/lib/config/createTLStore.ts +58 -3
  212. package/src/lib/config/defaultAssets.ts +19 -0
  213. package/src/lib/config/defaultShapes.ts +1 -1
  214. package/src/lib/editor/Editor.ts +448 -36
  215. package/src/lib/editor/assets/AssetUtil.ts +85 -0
  216. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +1 -1
  217. package/src/lib/editor/managers/FontManager/FontManager.test.ts +9 -2
  218. package/src/lib/editor/managers/FontManager/FontManager.ts +1 -67
  219. package/src/lib/editor/managers/PerformanceManager/PerformanceApiAdapter.ts +82 -0
  220. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.test.ts +522 -0
  221. package/src/lib/editor/managers/PerformanceManager/PerformanceManager.ts +583 -0
  222. package/src/lib/editor/managers/PerformanceManager/perf-types.ts +196 -0
  223. package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +1 -1
  224. package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +1 -1
  225. package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +5 -5
  226. package/src/lib/editor/managers/TextManager/TextManager.test.ts +18 -4
  227. package/src/lib/editor/managers/TextManager/TextManager.ts +140 -34
  228. package/src/lib/editor/managers/ThemeManager/ThemeManager.ts +116 -0
  229. package/src/lib/editor/managers/ThemeManager/defaultThemes.ts +605 -0
  230. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +25 -31
  231. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +7 -5
  232. package/src/lib/editor/shapes/ShapeUtil.ts +41 -5
  233. package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +1 -1
  234. package/src/lib/editor/shapes/shared/getPerfectDashProps.ts +7 -0
  235. package/src/lib/editor/tools/StateNode.ts +16 -18
  236. package/src/lib/editor/types/SvgExportContext.tsx +5 -0
  237. package/src/lib/editor/types/clipboard-types.ts +2 -1
  238. package/src/lib/editor/types/external-content.ts +1 -0
  239. package/src/lib/exports/StyleEmbedder.ts +1 -1
  240. package/src/lib/exports/getSvgJsx.tsx +22 -16
  241. package/src/lib/globals/environment.ts +18 -0
  242. package/src/lib/hooks/{useIsDarkMode.ts → useColorMode.ts} +9 -5
  243. package/src/lib/hooks/useCursor.ts +3 -7
  244. package/src/lib/hooks/useDarkMode.ts +4 -4
  245. package/src/lib/hooks/useEditorComponents.tsx +1 -1
  246. package/src/lib/hooks/useGestureEvents.ts +240 -168
  247. package/src/lib/hooks/useLocalStore.ts +1 -1
  248. package/src/lib/options.ts +108 -0
  249. package/src/lib/primitives/Box.test.ts +30 -0
  250. package/src/lib/primitives/Box.ts +1 -1
  251. package/src/lib/primitives/geometry/Arc2d.ts +2 -2
  252. package/src/lib/primitives/geometry/Circle2d.ts +2 -2
  253. package/src/lib/primitives/geometry/Ellipse2d.ts +2 -2
  254. package/src/lib/primitives/geometry/Geometry2d.test.ts +21 -0
  255. package/src/lib/primitives/geometry/Geometry2d.ts +4 -3
  256. package/src/lib/primitives/geometry/Polyline2d.ts +1 -1
  257. package/src/lib/primitives/geometry/Stadium2d.ts +1 -1
  258. package/src/lib/utils/getSvgPathFromPoints.ts +1 -1
  259. package/src/lib/utils/reparenting.ts +6 -2
  260. package/src/lib/utils/richText.ts +1 -1
  261. package/src/lib/utils/runtime.ts +3 -1
  262. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +1 -1
  263. package/src/lib/utils/sync/TLLocalSyncClient.ts +1 -1
  264. package/src/lib/utils/sync/hardReset.ts +0 -8
  265. package/src/version.ts +3 -3
  266. package/dist-cjs/lib/config/createTLUser.js.map +0 -7
  267. package/dist-cjs/lib/hooks/useIsDarkMode.js.map +0 -7
  268. package/dist-esm/lib/config/createTLUser.mjs.map +0 -7
  269. package/dist-esm/lib/hooks/useIsDarkMode.mjs +0 -15
  270. package/dist-esm/lib/hooks/useIsDarkMode.mjs.map +0 -7
@@ -10,10 +10,10 @@ import {
10
10
  import {
11
11
  ComputedCache,
12
12
  RecordType,
13
- StoreSideEffects,
14
- StoreSnapshot,
15
13
  UnknownRecord,
16
14
  reverseRecordsDiff,
15
+ StoreSnapshot,
16
+ StoreSideEffects,
17
17
  } from '@tldraw/store'
18
18
  import {
19
19
  CameraRecordType,
@@ -50,9 +50,16 @@ import {
50
50
  TLShapePartial,
51
51
  TLStore,
52
52
  TLStoreSnapshot,
53
+ TLTheme,
54
+ TLThemeId,
55
+ TLThemes,
56
+ TLUser,
57
+ TLUserId,
53
58
  TLVideoAsset,
59
+ UserRecordType,
54
60
  createBindingId,
55
61
  createShapeId,
62
+ createUserId,
56
63
  getShapePropKeysByStyle,
57
64
  isPageId,
58
65
  isShapeId,
@@ -90,15 +97,16 @@ import {
90
97
  uniqueId,
91
98
  } from '@tldraw/utils'
92
99
  import EventEmitter from 'eventemitter3'
100
+ import { TLCurrentUser, createTLCurrentUser } from '../config/createTLCurrentUser'
101
+ import { TLAnyAssetUtilConstructor, checkAssets } from '../config/defaultAssets'
102
+ import { TLAnyBindingUtilConstructor, checkBindings } from '../config/defaultBindings'
103
+ import { TLAnyShapeUtilConstructor, checkShapesAndAddCore } from '../config/defaultShapes'
93
104
  import {
94
105
  TLEditorSnapshot,
95
106
  TLLoadSnapshotOptions,
96
107
  getSnapshot,
97
108
  loadSnapshot,
98
109
  } from '../config/TLEditorSnapshot'
99
- import { TLUser, createTLUser } from '../config/createTLUser'
100
- import { TLAnyBindingUtilConstructor, checkBindings } from '../config/defaultBindings'
101
- import { TLAnyShapeUtilConstructor, checkShapesAndAddCore } from '../config/defaultShapes'
102
110
  import {
103
111
  DEFAULT_ANIMATION_OPTIONS,
104
112
  DEFAULT_CAMERA_OPTIONS,
@@ -115,14 +123,13 @@ import { tlmenus } from '../globals/menus'
115
123
  import { tltime } from '../globals/time'
116
124
  import { TldrawOptions, defaultTldrawOptions } from '../options'
117
125
  import { Box, BoxLike } from '../primitives/Box'
118
- import { Mat, MatLike } from '../primitives/Mat'
119
- import { Vec, VecLike } from '../primitives/Vec'
120
126
  import { EASINGS } from '../primitives/easings'
121
127
  import { Geometry2d } from '../primitives/geometry/Geometry2d'
122
128
  import { Group2d } from '../primitives/geometry/Group2d'
123
129
  import { intersectPolygonPolygon } from '../primitives/intersect'
130
+ import { Mat, MatLike } from '../primitives/Mat'
124
131
  import { PI, approximately, areAnglesCompatible, clamp, pointInPolygon } from '../primitives/utils'
125
- import { ReadonlySharedStyleMap, SharedStyle, SharedStyleMap } from '../utils/SharedStylesMap'
132
+ import { Vec, VecLike } from '../primitives/Vec'
126
133
  import { areShapesContentEqual } from '../utils/areShapesContentEqual'
127
134
  import { dataUrlToFile } from '../utils/assets'
128
135
  import { debugFlags } from '../utils/debug-flags'
@@ -137,6 +144,8 @@ import { getReorderingShapesChanges } from '../utils/reorderShapes'
137
144
  import { getDroppedShapesToNewParents, kickoutOccludedShapes } from '../utils/reparenting'
138
145
  import { TLTextOptions, TiptapEditor } from '../utils/richText'
139
146
  import { applyRotationToSnapshotShapes, getRotationSnapshot } from '../utils/rotation'
147
+ import { ReadonlySharedStyleMap, SharedStyle, SharedStyleMap } from '../utils/SharedStylesMap'
148
+ import { AssetUtil } from './assets/AssetUtil'
140
149
  import { BindingOnDeleteOptions, BindingUtil } from './bindings/BindingUtil'
141
150
  import { bindingsIndex } from './derivations/bindingsIndex'
142
151
  import { notVisibleShapes } from './derivations/notVisibleShapes'
@@ -148,10 +157,12 @@ import { FocusManager } from './managers/FocusManager/FocusManager'
148
157
  import { FontManager } from './managers/FontManager/FontManager'
149
158
  import { HistoryManager } from './managers/HistoryManager/HistoryManager'
150
159
  import { InputsManager } from './managers/InputsManager/InputsManager'
160
+ import { PerformanceManager } from './managers/PerformanceManager/PerformanceManager'
151
161
  import { ScribbleManager } from './managers/ScribbleManager/ScribbleManager'
152
162
  import { SnapManager } from './managers/SnapManager/SnapManager'
153
163
  import { SpatialIndexManager } from './managers/SpatialIndexManager/SpatialIndexManager'
154
164
  import { TextManager } from './managers/TextManager/TextManager'
165
+ import { resolveThemes, ThemeManager } from './managers/ThemeManager/ThemeManager'
155
166
  import { TickManager } from './managers/TickManager/TickManager'
156
167
  import { UserPreferencesManager } from './managers/UserPreferencesManager/UserPreferencesManager'
157
168
  import {
@@ -210,18 +221,17 @@ export interface TLEditorOptions {
210
221
  */
211
222
  bindingUtils: readonly TLAnyBindingUtilConstructor[]
212
223
  /**
213
- * An array of tools to use in the editor. These will be used to handle events and manage user interactions in the editor.
224
+ * An array of asset utils to use in the editor. These will be used to handle asset-type-specific behavior.
214
225
  */
215
- tools: readonly TLStateNodeConstructor[]
226
+ assetUtils?: readonly TLAnyAssetUtilConstructor[]
216
227
  /**
217
- * Should return a containing html element which has all the styles applied to the editor. If not
218
- * given, the body element will be used.
228
+ * An array of tools to use in the editor. These will be used to handle events and manage user interactions in the editor.
219
229
  */
220
- getContainer(): HTMLElement
230
+ tools: readonly TLStateNodeConstructor[]
221
231
  /**
222
232
  * A user defined externally to replace the default user.
223
233
  */
224
- user?: TLUser
234
+ user?: TLCurrentUser
225
235
  /**
226
236
  * The editor's initial active tool (or other state node id).
227
237
  */
@@ -230,25 +240,13 @@ export interface TLEditorOptions {
230
240
  * Whether to automatically focus the editor when it mounts.
231
241
  */
232
242
  autoFocus?: boolean
233
- /**
234
- * Whether to infer dark mode from the user's system preferences. Defaults to false.
235
- */
236
- inferDarkMode?: boolean
237
- /**
238
- * Options for the editor's camera.
239
- *
240
- * @deprecated Use `options.cameraOptions` instead. This will be removed in a future release.
241
- */
242
- cameraOptions?: Partial<TLCameraOptions>
243
- options?: Partial<TldrawOptions>
244
- /**
245
- * Text options for the editor.
246
- *
247
- * @deprecated Use `options.text` instead. This prop will be removed in a future release.
248
- */
249
- textOptions?: TLTextOptions
250
243
  licenseKey?: string
251
244
  fontAssetUrls?: { [key: string]: string | undefined }
245
+ /**
246
+ * Should return a containing html element which has all the styles applied to the editor. If not
247
+ * given, the body element will be used.
248
+ */
249
+ getContainer(): HTMLElement
252
250
  /**
253
251
  * Provides a way to hide shapes.
254
252
  *
@@ -268,6 +266,41 @@ export interface TLEditorOptions {
268
266
  shape: TLShape,
269
267
  editor: Editor
270
268
  ): 'visible' | 'hidden' | 'inherit' | null | undefined
269
+ /**
270
+ * Named theme definitions for the editor. Each theme contains shared
271
+ * properties (font size, line height, stroke width) and color palettes
272
+ * for both light and dark modes.
273
+ */
274
+ themes?: Partial<TLThemes>
275
+ /**
276
+ * The id of the initially active theme. Defaults to `'default'`.
277
+ */
278
+ initialTheme?: TLThemeId
279
+ /**
280
+ * The editor's color scheme preference, controls the default color mode. Defaults to `'light'`.
281
+ *
282
+ * - `'light'` - Always use light mode.
283
+ * - `'dark'` - Always use dark mode.
284
+ * - `'system'` - Follow the OS color scheme preference.
285
+ */
286
+ colorScheme?: 'light' | 'dark' | 'system'
287
+ /**
288
+ * Additional configuration options for the tldraw editor.
289
+ */
290
+ options?: Partial<TldrawOptions>
291
+ // --- Deprecated ----
292
+ /**
293
+ * Options for the editor's camera.
294
+ *
295
+ * @deprecated Use `options.cameraOptions` instead. This will be removed in a future release.
296
+ */
297
+ cameraOptions?: Partial<TLCameraOptions>
298
+ /**
299
+ * Text options for the editor.
300
+ *
301
+ * @deprecated Use `options.text` instead. This prop will be removed in a future release.
302
+ */
303
+ textOptions?: TLTextOptions
271
304
  }
272
305
 
273
306
  /**
@@ -296,6 +329,7 @@ export class Editor extends EventEmitter<TLEventMap> {
296
329
  user,
297
330
  shapeUtils,
298
331
  bindingUtils,
332
+ assetUtils: assetUtilConstructors,
299
333
  tools,
300
334
  getContainer,
301
335
  // needs to be here for backwards compatibility with TldrawEditor
@@ -303,13 +337,15 @@ export class Editor extends EventEmitter<TLEventMap> {
303
337
  cameraOptions,
304
338
  initialState,
305
339
  autoFocus,
306
- inferDarkMode,
307
340
  options: _options,
308
341
  // needs to be here for backwards compatibility with TldrawEditor
309
342
  // eslint-disable-next-line @typescript-eslint/no-deprecated
310
343
  textOptions: _textOptions,
311
344
  getShapeVisibility,
345
+ colorScheme,
312
346
  fontAssetUrls,
347
+ themes,
348
+ initialTheme,
313
349
  }: TLEditorOptions) {
314
350
  super()
315
351
 
@@ -344,21 +380,36 @@ export class Editor extends EventEmitter<TLEventMap> {
344
380
  ...options?.camera,
345
381
  })
346
382
 
383
+ this.getContainer = getContainer
384
+
347
385
  this._textOptions = atom('text options', options?.text ?? null)
348
386
 
349
- this.user = new UserPreferencesManager(user ?? createTLUser(), inferDarkMode ?? false)
387
+ this.user = new UserPreferencesManager(user ?? createTLCurrentUser(), colorScheme ?? 'light')
350
388
  this.disposables.add(() => this.user.dispose())
351
389
 
352
- this.getContainer = getContainer
353
-
354
390
  this.textMeasure = new TextManager(this)
355
391
  this.disposables.add(() => this.textMeasure.dispose())
356
392
 
357
- this.fonts = new FontManager(this, fontAssetUrls)
393
+ this._themeManager = new ThemeManager(this, {
394
+ themes: resolveThemes(themes),
395
+ initial: initialTheme ?? 'default',
396
+ })
397
+ this.disposables.add(() => this._themeManager.dispose())
358
398
 
359
399
  this._tickManager = new TickManager(this)
400
+ this.disposables.add(() => this._tickManager.dispose())
401
+ this.disposables.add(() => {
402
+ // Reset camera state to 'idle' so the store isn't left stuck at 'moving'
403
+ // when tick events stop (e.g. React strict mode disposes while camera is moving)
404
+ this.off('tick', this._decayCameraStateTimeout)
405
+ this._setCameraState('idle')
406
+ })
407
+
408
+ this.fonts = new FontManager(this, fontAssetUrls)
360
409
 
361
410
  this.inputs = new InputsManager(this)
411
+ this.performance = new PerformanceManager(this)
412
+ this.disposables.add(() => this.performance.dispose())
362
413
 
363
414
  class NewRoot extends RootState {
364
415
  static override initial = initialState ?? ''
@@ -396,6 +447,17 @@ export class Editor extends EventEmitter<TLEventMap> {
396
447
  this.shapeUtils = _shapeUtils
397
448
  this.styleProps = _styleProps
398
449
 
450
+ const _shapeUtilsByAssetType = {} as Record<string, ShapeUtil<any>>
451
+ for (const Util of allShapeUtils) {
452
+ const assetTypes = Util.handledAssetTypes
453
+ if (assetTypes) {
454
+ for (const assetType of assetTypes) {
455
+ _shapeUtilsByAssetType[assetType] = _shapeUtils[Util.type]
456
+ }
457
+ }
458
+ }
459
+ this._shapeUtilsByAssetType = _shapeUtilsByAssetType
460
+
399
461
  const allBindingUtils = checkBindings(bindingUtils)
400
462
  const _bindingUtils = {} as Record<string, BindingUtil<any>>
401
463
  for (const Util of allBindingUtils) {
@@ -404,6 +466,17 @@ export class Editor extends EventEmitter<TLEventMap> {
404
466
  }
405
467
  this.bindingUtils = _bindingUtils
406
468
 
469
+ // Asset utils
470
+ if (assetUtilConstructors) {
471
+ const allAssetUtils = checkAssets(assetUtilConstructors)
472
+ const _assetUtils = {} as Record<string, AssetUtil<any>>
473
+ for (const Util of allAssetUtils) {
474
+ const util = new Util(this)
475
+ _assetUtils[Util.type] = util
476
+ }
477
+ this.assetUtils = _assetUtils
478
+ }
479
+
407
480
  // Tools.
408
481
  // Accept tools from constructor parameters which may not conflict with the root note's default or
409
482
  // "baked in" tools, select and zoom.
@@ -820,6 +893,15 @@ export class Editor extends EventEmitter<TLEventMap> {
820
893
  })
821
894
  )
822
895
  }
896
+
897
+ this.disposables.add(
898
+ react('sync current user record', () => {
899
+ const user = this.store.props.users.currentUser.get()
900
+ if (user) {
901
+ this._ensureUserRecord(user)
902
+ }
903
+ })
904
+ )
823
905
  }
824
906
 
825
907
  private readonly _getShapeVisibility?: TLEditorOptions['getShapeVisibility']
@@ -929,6 +1011,18 @@ export class Editor extends EventEmitter<TLEventMap> {
929
1011
  */
930
1012
  readonly snaps: SnapManager
931
1013
 
1014
+ /**
1015
+ * A manager for performance measurement hooks.
1016
+ *
1017
+ * @public
1018
+ */
1019
+ readonly performance: PerformanceManager
1020
+
1021
+ /**
1022
+ * A manager for the spatial index, tracking where shapes exist on the canvas.
1023
+ *
1024
+ * @internal
1025
+ */
932
1026
  private readonly _spatialIndex: SpatialIndexManager
933
1027
 
934
1028
  /**
@@ -946,6 +1040,13 @@ export class Editor extends EventEmitter<TLEventMap> {
946
1040
  */
947
1041
  readonly user: UserPreferencesManager
948
1042
 
1043
+ /**
1044
+ * A manager for the editor's themes.
1045
+ *
1046
+ * @internal
1047
+ */
1048
+ private readonly _themeManager: ThemeManager
1049
+
949
1050
  /**
950
1051
  * A helper for measuring text.
951
1052
  *
@@ -1026,13 +1127,134 @@ export class Editor extends EventEmitter<TLEventMap> {
1026
1127
  * @public
1027
1128
  */
1028
1129
  dispose() {
1130
+ // Stop any in-progress camera animations and following before
1131
+ // running disposables, so their cleanup listeners fire first
1132
+ this.stopCameraAnimation()
1133
+ if (this.getInstanceState().followingUserId) {
1134
+ this.stopFollowingUser()
1135
+ }
1136
+
1029
1137
  this.disposables.forEach((dispose) => dispose())
1030
1138
  this.disposables.clear()
1139
+
1140
+ // Clear any open menus for this editor's context
1141
+ this.menus.clearOpenMenus()
1142
+
1031
1143
  this.store.dispose()
1032
1144
  this.isDisposed = true
1033
1145
  this.emit('dispose')
1034
1146
  }
1035
1147
 
1148
+ /* ------------------ Themes (shadowing the theme manager) ------------------ */
1149
+
1150
+ /**
1151
+ * Get the current color mode (`'light'` or `'dark'`), based on the user's dark mode preference.
1152
+ *
1153
+ * @public
1154
+ */
1155
+ getColorMode(): 'light' | 'dark' {
1156
+ return this._themeManager.getColorMode()
1157
+ }
1158
+
1159
+ /**
1160
+ * Set the color mode. Note that this is a convenience method that passes the mode to
1161
+ * `user.updateUserPreferences`, which is the source of truth for the user's color mode preference.
1162
+ *
1163
+ * @public
1164
+ */
1165
+ setColorMode(mode: 'light' | 'dark') {
1166
+ this.user.updateUserPreferences({ colorScheme: mode })
1167
+ return this
1168
+ }
1169
+
1170
+ /**
1171
+ * Get the id of the current theme.
1172
+ *
1173
+ * @public
1174
+ */
1175
+ getCurrentThemeId(): TLThemeId {
1176
+ return this._themeManager.getCurrentThemeId()
1177
+ }
1178
+
1179
+ /**
1180
+ * Get the current theme definition.
1181
+ *
1182
+ * @public
1183
+ */
1184
+ getCurrentTheme(): TLTheme {
1185
+ return this._themeManager.getCurrentTheme()
1186
+ }
1187
+
1188
+ /**
1189
+ * Set the current theme by id.
1190
+ *
1191
+ * @public
1192
+ */
1193
+ setCurrentTheme(id: TLThemeId) {
1194
+ this._themeManager.setCurrentTheme(id)
1195
+ return this
1196
+ }
1197
+
1198
+ /**
1199
+ * Get all registered theme definitions.
1200
+ *
1201
+ * @public
1202
+ */
1203
+ getThemes(): TLThemes {
1204
+ return this._themeManager.getThemes()
1205
+ }
1206
+
1207
+ /**
1208
+ * Get a single theme definition by id.
1209
+ *
1210
+ * @public
1211
+ */
1212
+ getTheme(id: TLThemeId): TLTheme | undefined {
1213
+ return this._themeManager.getTheme(id)
1214
+ }
1215
+
1216
+ /**
1217
+ * Replace all theme definitions, or update them via a callback that receives a deep copy.
1218
+ * The `'default'` theme must always be present in the result.
1219
+ *
1220
+ * @example
1221
+ * ```ts
1222
+ * // Replace all themes
1223
+ * editor.updateThemes({ default: myDefaultTheme, ocean: myOceanTheme })
1224
+ *
1225
+ * // Update via callback
1226
+ * editor.updateThemes((themes) => {
1227
+ * delete themes.ocean
1228
+ * return themes
1229
+ * })
1230
+ * ```
1231
+ *
1232
+ * @public
1233
+ */
1234
+ updateThemes(themes: TLThemes | ((themes: TLThemes) => TLThemes)) {
1235
+ this._themeManager.updateThemes(themes)
1236
+ return this
1237
+ }
1238
+
1239
+ /**
1240
+ * Register or update a single theme definition. The theme is keyed by its `id` property.
1241
+ *
1242
+ * @example
1243
+ * ```ts
1244
+ * // Override a property on the default theme
1245
+ * editor.updateTheme({ ...editor.getTheme('default')!, fontSize: 24 })
1246
+ *
1247
+ * // Register a new theme
1248
+ * editor.updateTheme({ id: 'ocean', ...myOceanTheme })
1249
+ * ```
1250
+ *
1251
+ * @public
1252
+ */
1253
+ updateTheme(theme: TLTheme) {
1254
+ this._themeManager.updateTheme(theme)
1255
+ return this
1256
+ }
1257
+
1036
1258
  /* ------------------- Shape Utils ------------------ */
1037
1259
 
1038
1260
  /**
@@ -1042,6 +1264,9 @@ export class Editor extends EventEmitter<TLEventMap> {
1042
1264
  */
1043
1265
  shapeUtils: { readonly [K in string]?: ShapeUtil<TLShape> }
1044
1266
 
1267
+ /** @internal */
1268
+ private _shapeUtilsByAssetType: { readonly [K in string]?: ShapeUtil<TLShape> } = {}
1269
+
1045
1270
  styleProps: { [key: string]: Map<StyleProp<any>, string> }
1046
1271
 
1047
1272
  /**
@@ -1084,6 +1309,18 @@ export class Editor extends EventEmitter<TLEventMap> {
1084
1309
  return hasOwnProperty(this.shapeUtils, type)
1085
1310
  }
1086
1311
 
1312
+ /**
1313
+ * Get the shape util that handles the given asset type.
1314
+ * Returns the shape util whose {@link ShapeUtil.handledAssetTypes} includes
1315
+ * the given asset type, or undefined if none matches.
1316
+ *
1317
+ * @param assetType - The asset type string.
1318
+ * @public
1319
+ */
1320
+ getShapeUtilForAssetType(assetType: string): ShapeUtil | undefined {
1321
+ return getOwnProperty(this._shapeUtilsByAssetType, assetType)
1322
+ }
1323
+
1087
1324
  /* ------------------- Binding Utils ------------------ */
1088
1325
  /**
1089
1326
  * A map of shape utility classes (TLShapeUtils) by shape type.
@@ -1119,6 +1356,56 @@ export class Editor extends EventEmitter<TLEventMap> {
1119
1356
  return bindingUtil
1120
1357
  }
1121
1358
 
1359
+ /* ------------------- Asset Utils ------------------ */
1360
+
1361
+ /**
1362
+ * A map of asset utility classes by asset type.
1363
+ *
1364
+ * @public
1365
+ */
1366
+ assetUtils: { readonly [K in string]?: AssetUtil<TLAsset> } = {}
1367
+
1368
+ /**
1369
+ * Get an asset util from an asset or asset type.
1370
+ *
1371
+ * @param arg - An asset, asset type string, or object with type.
1372
+ *
1373
+ * @public
1374
+ */
1375
+ getAssetUtil<S extends TLAsset>(asset: S | { type: S['type'] }): AssetUtil<S>
1376
+ getAssetUtil(type: string): AssetUtil
1377
+ getAssetUtil(arg: string | { type: string }) {
1378
+ const type = typeof arg === 'string' ? arg : arg.type
1379
+ const assetUtil = getOwnProperty(this.assetUtils, type)
1380
+ assert(assetUtil, `No asset util found for type "${type}"`)
1381
+ return assetUtil
1382
+ }
1383
+
1384
+ /**
1385
+ * Returns true if the editor has an asset util for the given asset type.
1386
+ *
1387
+ * @public
1388
+ */
1389
+ hasAssetUtil(arg: string | { type: string }): boolean {
1390
+ const type = typeof arg === 'string' ? arg : arg.type
1391
+ return hasOwnProperty(this.assetUtils, type)
1392
+ }
1393
+
1394
+ /**
1395
+ * Get the asset util that accepts the given MIME type.
1396
+ * Returns null if no registered asset util accepts the MIME type.
1397
+ *
1398
+ * @public
1399
+ */
1400
+ getAssetUtilForMimeType(mimeType: string): AssetUtil | null {
1401
+ for (const util of Object.values(this.assetUtils)) {
1402
+ if (util && util.acceptsMimeType(mimeType)) {
1403
+ return util
1404
+ }
1405
+ }
1406
+ return null
1407
+ }
1408
+
1122
1409
  /* --------------------- History -------------------- */
1123
1410
 
1124
1411
  /**
@@ -1142,6 +1429,7 @@ export class Editor extends EventEmitter<TLEventMap> {
1142
1429
  this._flushEventsForTick(0)
1143
1430
  this.complete()
1144
1431
  this.history.undo()
1432
+ this.performance._notifyUndoRedo('undo', this.history.getNumUndos(), this.history.getNumRedos())
1145
1433
  return this
1146
1434
  }
1147
1435
 
@@ -1172,6 +1460,7 @@ export class Editor extends EventEmitter<TLEventMap> {
1172
1460
  this._flushEventsForTick(0)
1173
1461
  this.complete()
1174
1462
  this.history.redo()
1463
+ this.performance._notifyUndoRedo('redo', this.history.getNumUndos(), this.history.getNumRedos())
1175
1464
  return this
1176
1465
  }
1177
1466
 
@@ -3972,6 +4261,94 @@ export class Editor extends EventEmitter<TLEventMap> {
3972
4261
  return this.getCollaborators().filter((c) => c.currentPageId === currentPageId)
3973
4262
  }
3974
4263
 
4264
+ // Attribution
4265
+
4266
+ /**
4267
+ * Get the current user's ID for attribution purposes.
4268
+ * Also ensures a `user:` record exists in the store for the current user.
4269
+ * Returns `null` when the user store has no current user.
4270
+ *
4271
+ * @public
4272
+ */
4273
+ getAttributionUserId(): string | null {
4274
+ const user = this.store.props.users.currentUser.get()
4275
+ if (!user) return null
4276
+ this._ensureUserRecord(user)
4277
+ return UserRecordType.parseId(user.id)
4278
+ }
4279
+
4280
+ /**
4281
+ * Ensure a user record exists in the store for the given user,
4282
+ * updating it if the data has changed.
4283
+ *
4284
+ * @internal
4285
+ */
4286
+ _ensureUserRecord(user: TLUser): void {
4287
+ const existing = this.store.get(user.id)
4288
+ if (
4289
+ existing &&
4290
+ existing.name === user.name &&
4291
+ existing.color === user.color &&
4292
+ existing.imageUrl === user.imageUrl &&
4293
+ existing.meta === user.meta
4294
+ ) {
4295
+ return
4296
+ }
4297
+ this.run(
4298
+ () => {
4299
+ this.store.put([user])
4300
+ },
4301
+ { history: 'ignore' }
4302
+ )
4303
+ }
4304
+
4305
+ /**
4306
+ * Resolve a display name for a user ID. Asks the
4307
+ * {@link @tldraw/tlschema#TLUserStore} first (the app's source of truth),
4308
+ * falling back to the `user:` record in the store.
4309
+ *
4310
+ * @public
4311
+ */
4312
+ getAttributionDisplayName(userId: string | null): string | null {
4313
+ if (!userId) return null
4314
+ return (
4315
+ this.store.props.users.resolve(userId).get()?.name ??
4316
+ this.store.get(createUserId(userId))?.name ??
4317
+ null
4318
+ )
4319
+ }
4320
+
4321
+ /**
4322
+ * Resolve a user record by ID. Asks the
4323
+ * {@link @tldraw/tlschema#TLUserStore} first (the app's source of truth),
4324
+ * falling back to the `user:` record in the store.
4325
+ *
4326
+ * @public
4327
+ */
4328
+ getAttributionUser(userId: string | null): TLUser | null {
4329
+ if (!userId) return null
4330
+ return (
4331
+ this.store.props.users.resolve(userId).get() ?? this.store.get(createUserId(userId)) ?? null
4332
+ )
4333
+ }
4334
+
4335
+ /**
4336
+ * Collect user IDs referenced by a set of shapes via shape-specific props
4337
+ * (e.g. `textFirstEditedBy` on notes).
4338
+ *
4339
+ * @internal
4340
+ */
4341
+ _getReferencedUserIds(shapes: TLShape[]): Set<string> {
4342
+ const userIds = new Set<string>()
4343
+ for (const shape of shapes) {
4344
+ const util = this.getShapeUtil(shape)
4345
+ for (const id of util.getReferencedUserIds(shape)) {
4346
+ userIds.add(id)
4347
+ }
4348
+ }
4349
+ return userIds
4350
+ }
4351
+
3975
4352
  // Following
3976
4353
 
3977
4354
  // When we are 'locked on' to a user, our camera is derived from their camera.
@@ -9071,6 +9448,7 @@ export class Editor extends EventEmitter<TLEventMap> {
9071
9448
  opts = {} as { force?: boolean }
9072
9449
  ): Promise<void> {
9073
9450
  if (!opts.force && this.getIsReadonly()) return
9451
+
9074
9452
  return this.externalContentHandlers[info.type]?.(info as any)
9075
9453
  }
9076
9454
 
@@ -9156,12 +9534,23 @@ export class Editor extends EventEmitter<TLEventMap> {
9156
9534
  assets.push(asset)
9157
9535
  }
9158
9536
 
9537
+ const users: TLUser[] = []
9538
+ const seenUserIds = new Set<TLUserId>()
9539
+ for (const userId of this._getReferencedUserIds(shapes)) {
9540
+ const recordId = createUserId(userId)
9541
+ if (seenUserIds.has(recordId)) continue
9542
+ seenUserIds.add(recordId)
9543
+ const user = this.store.get(recordId)
9544
+ if (user) users.push(user)
9545
+ }
9546
+
9159
9547
  return {
9160
9548
  schema: this.store.schema.serialize(),
9161
9549
  shapes,
9162
9550
  rootShapeIds,
9163
9551
  bindings,
9164
9552
  assets,
9553
+ users,
9165
9554
  }
9166
9555
  })
9167
9556
  }
@@ -9237,6 +9626,7 @@ export class Editor extends EventEmitter<TLEventMap> {
9237
9626
  const assets: TLAsset[] = []
9238
9627
  const shapes: TLShape[] = []
9239
9628
  const bindings: TLBinding[] = []
9629
+ const users: TLUser[] = []
9240
9630
 
9241
9631
  // Let's treat the content as a store, and then migrate that store.
9242
9632
  const store: StoreSnapshot<TLRecord> = {
@@ -9246,6 +9636,7 @@ export class Editor extends EventEmitter<TLEventMap> {
9246
9636
  ...Object.fromEntries(
9247
9637
  content.bindings?.map((bindings) => [bindings.id, bindings] as const) ?? []
9248
9638
  ),
9639
+ ...Object.fromEntries(content.users?.map((user) => [user.id, user] as const) ?? []),
9249
9640
  },
9250
9641
  schema: content.schema,
9251
9642
  }
@@ -9267,6 +9658,23 @@ export class Editor extends EventEmitter<TLEventMap> {
9267
9658
  bindings.push(record)
9268
9659
  break
9269
9660
  }
9661
+ case 'user': {
9662
+ users.push(record)
9663
+ break
9664
+ }
9665
+ }
9666
+ }
9667
+
9668
+ if (users.length > 0) {
9669
+ const existingUserIds = new Set(
9670
+ this.store
9671
+ .allRecords()
9672
+ .filter((r): r is TLUser => r.typeName === 'user')
9673
+ .map((r) => r.id)
9674
+ )
9675
+ const usersToCreate = users.filter((u) => !existingUserIds.has(u.id))
9676
+ if (usersToCreate.length > 0) {
9677
+ this.store.put(usersToCreate)
9270
9678
  }
9271
9679
  }
9272
9680
 
@@ -10457,6 +10865,7 @@ export class Editor extends EventEmitter<TLEventMap> {
10457
10865
  { immediate: true }
10458
10866
  )
10459
10867
 
10868
+ this.performance._notifyCameraOperation('zooming')
10460
10869
  this.emit('event', info)
10461
10870
  return // Stop here!
10462
10871
  }
@@ -10549,6 +10958,7 @@ export class Editor extends EventEmitter<TLEventMap> {
10549
10958
  immediate: true,
10550
10959
  })
10551
10960
  this.maybeTrackPerformance('Zooming')
10961
+ this.performance._notifyCameraOperation('zooming')
10552
10962
  this.root.handleEvent(info)
10553
10963
  this.emit('event', info)
10554
10964
  return
@@ -10559,6 +10969,7 @@ export class Editor extends EventEmitter<TLEventMap> {
10559
10969
  immediate: true,
10560
10970
  })
10561
10971
  this.maybeTrackPerformance('Panning')
10972
+ this.performance._notifyCameraOperation('panning')
10562
10973
  this.root.handleEvent(info)
10563
10974
  this.emit('event', info)
10564
10975
  return
@@ -10653,6 +11064,7 @@ export class Editor extends EventEmitter<TLEventMap> {
10653
11064
  immediate: true,
10654
11065
  })
10655
11066
  this.maybeTrackPerformance('Panning')
11067
+ this.performance._notifyCameraOperation('panning')
10656
11068
  return
10657
11069
  }
10658
11070