@tldraw/editor 3.16.0-canary.ffdf566dd0a8 → 3.16.0-internal.a478398270c6

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 (179) hide show
  1. package/dist-cjs/index.d.ts +16 -213
  2. package/dist-cjs/index.js +1 -8
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +0 -2
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/SVGContainer.js +1 -1
  7. package/dist-cjs/lib/components/SVGContainer.js.map +2 -2
  8. package/dist-cjs/lib/components/Shape.js +26 -4
  9. package/dist-cjs/lib/components/Shape.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultBrush.js +1 -1
  11. package/dist-cjs/lib/components/default-components/DefaultBrush.js.map +2 -2
  12. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -1
  13. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  14. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
  15. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +2 -2
  16. package/dist-cjs/lib/components/default-components/DefaultCursor.js +1 -1
  17. package/dist-cjs/lib/components/default-components/DefaultCursor.js.map +2 -2
  18. package/dist-cjs/lib/components/default-components/DefaultGrid.js +1 -1
  19. package/dist-cjs/lib/components/default-components/DefaultGrid.js.map +2 -2
  20. package/dist-cjs/lib/components/default-components/DefaultHandles.js +1 -1
  21. package/dist-cjs/lib/components/default-components/DefaultHandles.js.map +2 -2
  22. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +1 -1
  23. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  24. package/dist-cjs/lib/components/default-components/DefaultSnapIndictor.js +1 -1
  25. package/dist-cjs/lib/components/default-components/DefaultSnapIndictor.js.map +2 -2
  26. package/dist-cjs/lib/components/default-components/DefaultSpinner.js +15 -27
  27. package/dist-cjs/lib/components/default-components/DefaultSpinner.js.map +3 -3
  28. package/dist-cjs/lib/config/TLUserPreferences.js +2 -14
  29. package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
  30. package/dist-cjs/lib/editor/Editor.js +52 -107
  31. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  32. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +3 -13
  33. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  34. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  35. package/dist-cjs/lib/editor/tools/StateNode.js +1 -20
  36. package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
  37. package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
  38. package/dist-cjs/lib/hooks/useEditor.js +4 -1
  39. package/dist-cjs/lib/hooks/useEditor.js.map +2 -2
  40. package/dist-cjs/lib/hooks/useEditorComponents.js +0 -2
  41. package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
  42. package/dist-cjs/lib/license/Watermark.js +2 -2
  43. package/dist-cjs/lib/license/Watermark.js.map +2 -2
  44. package/dist-cjs/lib/options.js +0 -1
  45. package/dist-cjs/lib/options.js.map +2 -2
  46. package/dist-cjs/lib/primitives/geometry/Arc2d.js +1 -1
  47. package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
  48. package/dist-cjs/lib/primitives/geometry/Circle2d.js +1 -1
  49. package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +2 -2
  50. package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js +1 -3
  51. package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js.map +2 -2
  52. package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +1 -1
  53. package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +2 -2
  54. package/dist-cjs/lib/primitives/geometry/geometry-constants.js +2 -2
  55. package/dist-cjs/lib/primitives/geometry/geometry-constants.js.map +2 -2
  56. package/dist-cjs/lib/primitives/intersect.js +4 -4
  57. package/dist-cjs/lib/primitives/intersect.js.map +2 -2
  58. package/dist-cjs/lib/primitives/utils.js +0 -4
  59. package/dist-cjs/lib/primitives/utils.js.map +2 -2
  60. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +1 -0
  61. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  62. package/dist-cjs/version.js +3 -3
  63. package/dist-cjs/version.js.map +1 -1
  64. package/dist-esm/index.d.mts +16 -213
  65. package/dist-esm/index.mjs +2 -16
  66. package/dist-esm/index.mjs.map +2 -2
  67. package/dist-esm/lib/TldrawEditor.mjs +0 -2
  68. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  69. package/dist-esm/lib/components/SVGContainer.mjs +1 -1
  70. package/dist-esm/lib/components/SVGContainer.mjs.map +2 -2
  71. package/dist-esm/lib/components/Shape.mjs +26 -4
  72. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  73. package/dist-esm/lib/components/default-components/DefaultBrush.mjs +1 -1
  74. package/dist-esm/lib/components/default-components/DefaultBrush.mjs.map +2 -2
  75. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +1 -1
  76. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  77. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
  78. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +2 -2
  79. package/dist-esm/lib/components/default-components/DefaultCursor.mjs +1 -1
  80. package/dist-esm/lib/components/default-components/DefaultCursor.mjs.map +2 -2
  81. package/dist-esm/lib/components/default-components/DefaultGrid.mjs +1 -1
  82. package/dist-esm/lib/components/default-components/DefaultGrid.mjs.map +2 -2
  83. package/dist-esm/lib/components/default-components/DefaultHandles.mjs +1 -1
  84. package/dist-esm/lib/components/default-components/DefaultHandles.mjs.map +2 -2
  85. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +1 -1
  86. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  87. package/dist-esm/lib/components/default-components/DefaultSnapIndictor.mjs +1 -1
  88. package/dist-esm/lib/components/default-components/DefaultSnapIndictor.mjs.map +2 -2
  89. package/dist-esm/lib/components/default-components/DefaultSpinner.mjs +15 -17
  90. package/dist-esm/lib/components/default-components/DefaultSpinner.mjs.map +2 -2
  91. package/dist-esm/lib/config/TLUserPreferences.mjs +2 -14
  92. package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
  93. package/dist-esm/lib/editor/Editor.mjs +52 -107
  94. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  95. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +3 -13
  96. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  97. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  98. package/dist-esm/lib/editor/tools/StateNode.mjs +1 -20
  99. package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
  100. package/dist-esm/lib/hooks/useEditor.mjs +4 -1
  101. package/dist-esm/lib/hooks/useEditor.mjs.map +2 -2
  102. package/dist-esm/lib/hooks/useEditorComponents.mjs +0 -4
  103. package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
  104. package/dist-esm/lib/license/Watermark.mjs +2 -2
  105. package/dist-esm/lib/license/Watermark.mjs.map +2 -2
  106. package/dist-esm/lib/options.mjs +0 -1
  107. package/dist-esm/lib/options.mjs.map +2 -2
  108. package/dist-esm/lib/primitives/geometry/Arc2d.mjs +2 -2
  109. package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
  110. package/dist-esm/lib/primitives/geometry/Circle2d.mjs +2 -2
  111. package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +2 -2
  112. package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs +1 -3
  113. package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs.map +2 -2
  114. package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +2 -2
  115. package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +2 -2
  116. package/dist-esm/lib/primitives/geometry/geometry-constants.mjs +2 -2
  117. package/dist-esm/lib/primitives/geometry/geometry-constants.mjs.map +2 -2
  118. package/dist-esm/lib/primitives/intersect.mjs +5 -5
  119. package/dist-esm/lib/primitives/intersect.mjs.map +2 -2
  120. package/dist-esm/lib/primitives/utils.mjs +0 -4
  121. package/dist-esm/lib/primitives/utils.mjs.map +2 -2
  122. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +1 -0
  123. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  124. package/dist-esm/version.mjs +3 -3
  125. package/dist-esm/version.mjs.map +1 -1
  126. package/editor.css +27 -23
  127. package/package.json +8 -9
  128. package/src/index.ts +1 -15
  129. package/src/lib/TldrawEditor.tsx +0 -2
  130. package/src/lib/components/SVGContainer.tsx +1 -1
  131. package/src/lib/components/Shape.tsx +21 -6
  132. package/src/lib/components/default-components/DefaultBrush.tsx +1 -1
  133. package/src/lib/components/default-components/DefaultCanvas.tsx +1 -1
  134. package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
  135. package/src/lib/components/default-components/DefaultCursor.tsx +1 -1
  136. package/src/lib/components/default-components/DefaultGrid.tsx +1 -1
  137. package/src/lib/components/default-components/DefaultHandles.tsx +1 -5
  138. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +1 -1
  139. package/src/lib/components/default-components/DefaultSnapIndictor.tsx +1 -1
  140. package/src/lib/components/default-components/DefaultSpinner.tsx +12 -12
  141. package/src/lib/config/TLUserPreferences.ts +0 -14
  142. package/src/lib/editor/Editor.test.ts +0 -407
  143. package/src/lib/editor/Editor.ts +72 -140
  144. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +0 -34
  145. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +0 -13
  146. package/src/lib/editor/shapes/ShapeUtil.ts +0 -57
  147. package/src/lib/editor/tools/StateNode.ts +1 -27
  148. package/src/lib/editor/types/misc-types.ts +1 -73
  149. package/src/lib/hooks/useEditor.tsx +5 -6
  150. package/src/lib/hooks/useEditorComponents.tsx +2 -8
  151. package/src/lib/license/Watermark.tsx +2 -2
  152. package/src/lib/options.ts +0 -2
  153. package/src/lib/primitives/geometry/Arc2d.ts +2 -2
  154. package/src/lib/primitives/geometry/Circle2d.ts +2 -2
  155. package/src/lib/primitives/geometry/CubicBezier2d.ts +1 -4
  156. package/src/lib/primitives/geometry/Ellipse2d.ts +2 -2
  157. package/src/lib/primitives/geometry/geometry-constants.ts +1 -2
  158. package/src/lib/primitives/intersect.ts +5 -12
  159. package/src/lib/primitives/utils.ts +0 -11
  160. package/src/lib/test/currentToolIdMask.test.ts +49 -0
  161. package/src/lib/utils/sync/TLLocalSyncClient.ts +1 -0
  162. package/src/version.ts +3 -3
  163. package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js +0 -53
  164. package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js.map +0 -7
  165. package/dist-cjs/lib/hooks/useStateAttribute.js +0 -35
  166. package/dist-cjs/lib/hooks/useStateAttribute.js.map +0 -7
  167. package/dist-cjs/lib/utils/EditorAtom.js +0 -45
  168. package/dist-cjs/lib/utils/EditorAtom.js.map +0 -7
  169. package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs +0 -23
  170. package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs.map +0 -7
  171. package/dist-esm/lib/hooks/useStateAttribute.mjs +0 -15
  172. package/dist-esm/lib/hooks/useStateAttribute.mjs.map +0 -7
  173. package/dist-esm/lib/utils/EditorAtom.mjs +0 -25
  174. package/dist-esm/lib/utils/EditorAtom.mjs.map +0 -7
  175. package/src/lib/components/default-components/DefaultShapeWrapper.tsx +0 -35
  176. package/src/lib/editor/tools/StateNode.test.ts +0 -285
  177. package/src/lib/hooks/useStateAttribute.ts +0 -15
  178. package/src/lib/primitives/intersect.test.ts +0 -946
  179. package/src/lib/utils/EditorAtom.ts +0 -37
@@ -21,14 +21,13 @@ export function useMaybeEditor(): Editor | null {
21
21
  return React.useContext(EditorContext)
22
22
  }
23
23
 
24
- /** @public */
25
- export interface EditorProviderProps {
24
+ export function EditorProvider({
25
+ editor,
26
+ children,
27
+ }: {
26
28
  editor: Editor
27
29
  children: React.ReactNode
28
- }
29
-
30
- /** @public @react */
31
- export function EditorProvider({ editor, children }: EditorProviderProps) {
30
+ }) {
32
31
  return (
33
32
  <EditorContext.Provider value={editor}>
34
33
  <IdProvider>{children}</IdProvider>
@@ -1,4 +1,4 @@
1
- import { ComponentType, ReactNode, RefAttributes, createContext, useContext, useMemo } from 'react'
1
+ import { ComponentType, ReactNode, 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,10 +37,6 @@ 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'
44
40
  import {
45
41
  DefaultSnapIndicator,
46
42
  TLSnapIndicatorProps,
@@ -72,9 +68,8 @@ export interface TLEditorComponents {
72
68
  SelectionForeground?: ComponentType<TLSelectionForegroundProps> | null
73
69
  ShapeIndicator?: ComponentType<TLShapeIndicatorProps> | null
74
70
  ShapeIndicators?: ComponentType | null
75
- ShapeWrapper?: ComponentType<TLShapeWrapperProps & RefAttributes<HTMLDivElement>> | null
76
71
  SnapIndicator?: ComponentType<TLSnapIndicatorProps> | null
77
- Spinner?: ComponentType<React.SVGProps<SVGSVGElement>> | null
72
+ Spinner?: ComponentType | null
78
73
  SvgDefs?: ComponentType | null
79
74
  ZoomBrush?: ComponentType<TLBrushProps> | null
80
75
 
@@ -119,7 +114,6 @@ export function EditorComponentsProvider({
119
114
  SelectionForeground: DefaultSelectionForeground,
120
115
  ShapeIndicator: DefaultShapeIndicator,
121
116
  ShapeIndicators: DefaultShapeIndicators,
122
- ShapeWrapper: DefaultShapeWrapper,
123
117
  SnapIndicator: DefaultSnapIndicator,
124
118
  Spinner: DefaultSpinner,
125
119
  SvgDefs: DefaultSvgDefs,
@@ -143,7 +143,7 @@ To remove the watermark, please purchase a license at tldraw.dev.
143
143
  }
144
144
 
145
145
  .${className}:hover > button {
146
- animation: ${className}_delayed_link 0.2s forwards ease-in-out;
146
+ animation: delayed_link 0.2s forwards ease-in-out;
147
147
  animation-delay: 0.32s;
148
148
  }
149
149
 
@@ -153,7 +153,7 @@ To remove the watermark, please purchase a license at tldraw.dev.
153
153
  }
154
154
 
155
155
 
156
- @keyframes ${className}_delayed_link {
156
+ @keyframes delayed_link {
157
157
  0% {
158
158
  cursor: inherit;
159
159
  opacity: .38;
@@ -53,7 +53,6 @@ export interface TldrawOptions {
53
53
  readonly flattenImageBoundsPadding: number
54
54
  readonly laserDelayMs: number
55
55
  readonly maxExportDelayMs: number
56
- readonly tooltipDelayMs: number
57
56
  /**
58
57
  * How long should previews created by {@link Editor.createTemporaryAssetPreview} last before
59
58
  * they expire? Defaults to 3 minutes.
@@ -125,7 +124,6 @@ export const defaultTldrawOptions = {
125
124
  flattenImageBoundsPadding: 16,
126
125
  laserDelayMs: 1200,
127
126
  maxExportDelayMs: 5000,
128
- tooltipDelayMs: 700,
129
127
  temporaryAssetPreviewLifetimeMs: 180000,
130
128
  actionShortcutsLocation: 'swap',
131
129
  createTextOnCanvasDoubleClick: true,
@@ -2,7 +2,7 @@ import { Vec, VecLike } from '../Vec'
2
2
  import { intersectLineSegmentCircle } from '../intersect'
3
3
  import { getArcMeasure, getPointInArcT, getPointOnCircle } from '../utils'
4
4
  import { Geometry2d, Geometry2dOptions } from './Geometry2d'
5
- import { getVerticesCountForArcLength } from './geometry-constants'
5
+ import { getVerticesCountForLength } from './geometry-constants'
6
6
 
7
7
  /** @public */
8
8
  export class Arc2d extends Geometry2d {
@@ -94,7 +94,7 @@ export class Arc2d extends Geometry2d {
94
94
  getVertices(): Vec[] {
95
95
  const { _center, _measure: measure, length, _radius: radius, _angleStart: angleStart } = this
96
96
  const vertices: Vec[] = []
97
- for (let i = 0, n = getVerticesCountForArcLength(Math.abs(length)); i < n + 1; i++) {
97
+ for (let i = 0, n = getVerticesCountForLength(Math.abs(length)); i < n + 1; i++) {
98
98
  const t = (i / n) * measure
99
99
  const angle = angleStart + t
100
100
  vertices.push(getPointOnCircle(_center, radius, angle))
@@ -3,7 +3,7 @@ import { Vec, VecLike } from '../Vec'
3
3
  import { intersectLineSegmentCircle } from '../intersect'
4
4
  import { PI2, getPointOnCircle } from '../utils'
5
5
  import { Geometry2d, Geometry2dOptions } from './Geometry2d'
6
- import { getVerticesCountForArcLength } from './geometry-constants'
6
+ import { getVerticesCountForLength } from './geometry-constants'
7
7
 
8
8
  /** @public */
9
9
  export class Circle2d extends Geometry2d {
@@ -36,7 +36,7 @@ export class Circle2d extends Geometry2d {
36
36
  const { _center, _radius: radius } = this
37
37
  const perimeter = PI2 * radius
38
38
  const vertices: Vec[] = []
39
- for (let i = 0, n = getVerticesCountForArcLength(perimeter); i < n; i++) {
39
+ for (let i = 0, n = getVerticesCountForLength(perimeter); i < n; i++) {
40
40
  const angle = (i / n) * PI2
41
41
  vertices.push(getPointOnCircle(_center, radius, angle))
42
42
  }
@@ -8,7 +8,6 @@ export class CubicBezier2d extends Polyline2d {
8
8
  private _b: Vec
9
9
  private _c: Vec
10
10
  private _d: Vec
11
- private _resolution: number
12
11
 
13
12
  constructor(
14
13
  config: Omit<Geometry2dOptions, 'isFilled' | 'isClosed'> & {
@@ -16,7 +15,6 @@ export class CubicBezier2d extends Polyline2d {
16
15
  cp1: Vec
17
16
  cp2: Vec
18
17
  end: Vec
19
- resolution?: number
20
18
  }
21
19
  ) {
22
20
  const { start: a, cp1: b, cp2: c, end: d } = config
@@ -26,14 +24,13 @@ export class CubicBezier2d extends Polyline2d {
26
24
  this._b = b
27
25
  this._c = c
28
26
  this._d = d
29
- this._resolution = config.resolution ?? 10
30
27
  }
31
28
 
32
29
  override getVertices() {
33
30
  const vertices = [] as Vec[]
34
31
  const { _a: a, _b: b, _c: c, _d: d } = this
35
32
  // we'll always use ten vertices for each bezier curve
36
- for (let i = 0, n = this._resolution; i <= n; i++) {
33
+ for (let i = 0, n = 10; i <= n; i++) {
37
34
  const t = i / n
38
35
  vertices.push(
39
36
  new Vec(
@@ -3,7 +3,7 @@ import { Vec, VecLike } from '../Vec'
3
3
  import { PI, PI2, clamp, perimeterOfEllipse } from '../utils'
4
4
  import { Edge2d } from './Edge2d'
5
5
  import { Geometry2d, Geometry2dOptions } from './Geometry2d'
6
- import { getVerticesCountForArcLength } from './geometry-constants'
6
+ import { getVerticesCountForLength } from './geometry-constants'
7
7
 
8
8
  /** @public */
9
9
  export class Ellipse2d extends Geometry2d {
@@ -47,7 +47,7 @@ export class Ellipse2d extends Geometry2d {
47
47
  const q = Math.pow(cx - cy, 2) / Math.pow(cx + cy, 2)
48
48
  const p = PI * (cx + cy) * (1 + (3 * q) / (10 + Math.sqrt(4 - 3 * q)))
49
49
  // Number of points
50
- const len = getVerticesCountForArcLength(p)
50
+ const len = getVerticesCountForLength(p)
51
51
  // Size of step
52
52
  const step = PI2 / len
53
53
 
@@ -1,7 +1,6 @@
1
1
  const SPACING = 20
2
2
  const MIN_COUNT = 8
3
3
 
4
- /** @internal */
5
- export function getVerticesCountForArcLength(length: number, spacing = SPACING) {
4
+ export function getVerticesCountForLength(length: number, spacing = SPACING) {
6
5
  return Math.max(MIN_COUNT, Math.ceil(length / spacing))
7
6
  }
@@ -1,5 +1,5 @@
1
1
  import { Box } from './Box'
2
- import { approximately, approximatelyLte, pointInPolygon } from './utils'
2
+ import { pointInPolygon } from './utils'
3
3
  import { Vec, VecLike } from './Vec'
4
4
 
5
5
  // need even more intersections? See https://gist.github.com/steveruizok/35c02d526c707003a5c79761bfb89a52
@@ -17,8 +17,7 @@ export function intersectLineSegmentLineSegment(
17
17
  a1: VecLike,
18
18
  a2: VecLike,
19
19
  b1: VecLike,
20
- b2: VecLike,
21
- precision = 1e-10
20
+ b2: VecLike
22
21
  ) {
23
22
  const ABx = a1.x - b1.x
24
23
  const ABy = a1.y - b1.y
@@ -30,19 +29,14 @@ export function intersectLineSegmentLineSegment(
30
29
  const ub_t = AVx * ABy - AVy * ABx
31
30
  const u_b = BVy * AVx - BVx * AVy
32
31
 
33
- if (approximately(ua_t, 0, precision) || approximately(ub_t, 0, precision)) return null // coincident
32
+ if (ua_t === 0 || ub_t === 0) return null // coincident
34
33
 
35
- if (approximately(u_b, 0, precision)) return null // parallel
34
+ if (u_b === 0) return null // parallel
36
35
 
37
36
  if (u_b !== 0) {
38
37
  const ua = ua_t / u_b
39
38
  const ub = ub_t / u_b
40
- if (
41
- approximatelyLte(0, ua, precision) &&
42
- approximatelyLte(ua, 1, precision) &&
43
- approximatelyLte(0, ub, precision) &&
44
- approximatelyLte(ub, 1, precision)
45
- ) {
39
+ if (0 <= ua && ua <= 1 && 0 <= ub && ub <= 1) {
46
40
  return Vec.AddXY(a1, ua * AVx, ua * AVy)
47
41
  }
48
42
  }
@@ -131,7 +125,6 @@ export function intersectLineSegmentPolygon(a1: VecLike, a2: VecLike, points: Ve
131
125
  points[i - 1],
132
126
  points[i % points.length]
133
127
  )
134
-
135
128
  if (segmentIntersection) result.push(segmentIntersection)
136
129
  }
137
130
 
@@ -77,17 +77,6 @@ export function approximately(a: number, b: number, precision = 0.000001) {
77
77
  return Math.abs(a - b) <= precision
78
78
  }
79
79
 
80
- /**
81
- * Whether a number is approximately less than or equal to another number.
82
- *
83
- * @param a - The first number.
84
- * @param b - The second number.
85
- * @public
86
- */
87
- export function approximatelyLte(a: number, b: number, precision = 0.000001) {
88
- return a < b || approximately(a, b, precision)
89
- }
90
-
91
80
  /**
92
81
  * Find the approximate perimeter of an ellipse.
93
82
  *
@@ -0,0 +1,49 @@
1
+ import { describe } from 'node:test'
2
+ import { createTLStore } from '../config/createTLStore'
3
+ import { Editor } from '../editor/Editor'
4
+ import { StateNode } from '../editor/tools/StateNode'
5
+
6
+ let editor: Editor
7
+
8
+ class A extends StateNode {
9
+ static override id = 'A'
10
+ }
11
+
12
+ class B extends StateNode {
13
+ static override id = 'B'
14
+ }
15
+
16
+ class C extends StateNode {
17
+ static override id = 'C'
18
+
19
+ override onEnter() {
20
+ this.setCurrentToolIdMask('A')
21
+ }
22
+ }
23
+
24
+ beforeEach(() => {
25
+ editor = new Editor({
26
+ initialState: 'A',
27
+ shapeUtils: [],
28
+ bindingUtils: [],
29
+ tools: [A, B, C],
30
+ store: createTLStore({ shapeUtils: [], bindingUtils: [] }),
31
+ getContainer: () => document.body,
32
+ })
33
+ })
34
+
35
+ describe('current tool id mask', () => {
36
+ it('starts with the correct tool id', () => {
37
+ expect(editor.getCurrentToolId()).toBe('A')
38
+ })
39
+
40
+ it('updates the current tool id', () => {
41
+ editor.setCurrentTool('B')
42
+ expect(editor.getCurrentToolId()).toBe('B')
43
+ })
44
+
45
+ it('masks the current tool id', () => {
46
+ editor.setCurrentTool('C')
47
+ expect(editor.getCurrentToolId()).toBe('A')
48
+ })
49
+ })
@@ -266,6 +266,7 @@ export class TLLocalSyncClient {
266
266
 
267
267
  private isPersisting = false
268
268
  private didLastWriteError = false
269
+ // eslint-disable-next-line no-restricted-globals
269
270
  private scheduledPersistTimeout: ReturnType<typeof setTimeout> | null = null
270
271
 
271
272
  /**
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.ffdf566dd0a8'
4
+ export const version = '3.16.0-internal.a478398270c6'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2025-08-06T13:55:07.190Z',
8
- patch: '2025-08-06T13:55:07.190Z',
7
+ minor: '2025-08-19T10:21:26.717Z',
8
+ patch: '2025-08-19T10:21:26.717Z',
9
9
  }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var DefaultShapeWrapper_exports = {};
30
- __export(DefaultShapeWrapper_exports, {
31
- DefaultShapeWrapper: () => DefaultShapeWrapper
32
- });
33
- module.exports = __toCommonJS(DefaultShapeWrapper_exports);
34
- var import_jsx_runtime = require("react/jsx-runtime");
35
- var import_classnames = __toESM(require("classnames"));
36
- var import_react = require("react");
37
- const DefaultShapeWrapper = (0, import_react.forwardRef)(function DefaultShapeWrapper2({ children, shape, isBackground, ...props }, ref) {
38
- const isFilledShape = "fill" in shape.props && shape.props.fill !== "none";
39
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
40
- "div",
41
- {
42
- ref,
43
- "data-shape-type": shape.type,
44
- "data-shape-is-filled": isBackground ? void 0 : isFilledShape,
45
- "data-shape-id": shape.id,
46
- draggable: false,
47
- ...props,
48
- className: (0, import_classnames.default)("tl-shape", isBackground && "tl-shape-background", props.className),
49
- children
50
- }
51
- );
52
- });
53
- //# sourceMappingURL=DefaultShapeWrapper.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/lib/components/default-components/DefaultShapeWrapper.tsx"],
4
- "sourcesContent": ["import { TLShape } from '@tldraw/tlschema'\nimport classNames from 'classnames'\nimport { forwardRef, ReactNode } from 'react'\n\n/** @public */\nexport interface TLShapeWrapperProps extends React.HTMLAttributes<HTMLDivElement> {\n\t/** The shape being rendered. */\n\tshape: TLShape\n\t/** Whether this is the shapes regular, or background component. */\n\tisBackground: boolean\n\t/** The shape's rendered component. */\n\tchildren: ReactNode\n}\n\n/** @public @react */\nexport const DefaultShapeWrapper = forwardRef(function DefaultShapeWrapper(\n\t{ children, shape, isBackground, ...props }: TLShapeWrapperProps,\n\tref: React.Ref<HTMLDivElement>\n) {\n\tconst isFilledShape = 'fill' in shape.props && shape.props.fill !== 'none'\n\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tdata-shape-type={shape.type}\n\t\t\tdata-shape-is-filled={isBackground ? undefined : isFilledShape}\n\t\t\tdata-shape-id={shape.id}\n\t\t\tdraggable={false}\n\t\t\t{...props}\n\t\t\tclassName={classNames('tl-shape', isBackground && 'tl-shape-background', props.className)}\n\t\t>\n\t\t\t{children}\n\t\t</div>\n\t)\n})\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBE;AArBF,wBAAuB;AACvB,mBAAsC;AAa/B,MAAM,0BAAsB,yBAAW,SAASA,qBACtD,EAAE,UAAU,OAAO,cAAc,GAAG,MAAM,GAC1C,KACC;AACD,QAAM,gBAAgB,UAAU,MAAM,SAAS,MAAM,MAAM,SAAS;AAEpE,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA,mBAAiB,MAAM;AAAA,MACvB,wBAAsB,eAAe,SAAY;AAAA,MACjD,iBAAe,MAAM;AAAA,MACrB,WAAW;AAAA,MACV,GAAG;AAAA,MACJ,eAAW,kBAAAC,SAAW,YAAY,gBAAgB,uBAAuB,MAAM,SAAS;AAAA,MAEvF;AAAA;AAAA,EACF;AAEF,CAAC;",
6
- "names": ["DefaultShapeWrapper", "classNames"]
7
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var useStateAttribute_exports = {};
20
- __export(useStateAttribute_exports, {
21
- useStateAttribute: () => useStateAttribute
22
- });
23
- module.exports = __toCommonJS(useStateAttribute_exports);
24
- var import_state = require("@tldraw/state");
25
- var import_react = require("react");
26
- var import_useEditor = require("./useEditor");
27
- function useStateAttribute() {
28
- const editor = (0, import_useEditor.useEditor)();
29
- (0, import_react.useLayoutEffect)(() => {
30
- return (0, import_state.react)("stateAttribute", () => {
31
- editor.getContainer().setAttribute("data-state", editor.getPath());
32
- });
33
- }, [editor]);
34
- }
35
- //# sourceMappingURL=useStateAttribute.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/lib/hooks/useStateAttribute.ts"],
4
- "sourcesContent": ["import { react } from '@tldraw/state'\nimport { useLayoutEffect } from 'react'\nimport { useEditor } from './useEditor'\n\nexport function useStateAttribute() {\n\tconst editor = useEditor()\n\n\t// we use a layout effect because we don't want there to be any perceptible delay between the\n\t// editor mounting and this attribute being applied, because styles may depend on it:\n\tuseLayoutEffect(() => {\n\t\treturn react('stateAttribute', () => {\n\t\t\teditor.getContainer().setAttribute('data-state', editor.getPath())\n\t\t})\n\t}, [editor])\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,mBAAgC;AAChC,uBAA0B;AAEnB,SAAS,oBAAoB;AACnC,QAAM,aAAS,4BAAU;AAIzB,oCAAgB,MAAM;AACrB,eAAO,oBAAM,kBAAkB,MAAM;AACpC,aAAO,aAAa,EAAE,aAAa,cAAc,OAAO,QAAQ,CAAC;AAAA,IAClE,CAAC;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AACZ;",
6
- "names": []
7
- }
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var EditorAtom_exports = {};
20
- __export(EditorAtom_exports, {
21
- EditorAtom: () => EditorAtom
22
- });
23
- module.exports = __toCommonJS(EditorAtom_exports);
24
- var import_state = require("@tldraw/state");
25
- var import_utils = require("@tldraw/utils");
26
- class EditorAtom {
27
- constructor(name, getInitialState) {
28
- this.name = name;
29
- this.getInitialState = getInitialState;
30
- }
31
- states = new import_utils.WeakCache();
32
- getAtom(editor) {
33
- return this.states.get(editor, () => (0, import_state.atom)(this.name, this.getInitialState(editor)));
34
- }
35
- get(editor) {
36
- return this.getAtom(editor).get();
37
- }
38
- update(editor, update) {
39
- return this.getAtom(editor).update(update);
40
- }
41
- set(editor, state) {
42
- return this.getAtom(editor).set(state);
43
- }
44
- }
45
- //# sourceMappingURL=EditorAtom.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/lib/utils/EditorAtom.ts"],
4
- "sourcesContent": ["import { atom, Atom } from '@tldraw/state'\nimport { WeakCache } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\n\n/**\n * An Atom that is scoped to the lifetime of an Editor.\n *\n * This is useful for storing UI state for tldraw applications. Keeping state scoped to an editor\n * instead of stored in a global atom can prevent issues with state being shared between editors\n * when navigating between pages, or when multiple editor instances are used on the same page.\n *\n * @public\n */\nexport class EditorAtom<T> {\n\tprivate states = new WeakCache<Editor, Atom<T>>()\n\n\tconstructor(\n\t\tprivate name: string,\n\t\tprivate getInitialState: (editor: Editor) => T\n\t) {}\n\n\tgetAtom(editor: Editor): Atom<T> {\n\t\treturn this.states.get(editor, () => atom(this.name, this.getInitialState(editor)))\n\t}\n\n\tget(editor: Editor): T {\n\t\treturn this.getAtom(editor).get()\n\t}\n\n\tupdate(editor: Editor, update: (state: T) => T): T {\n\t\treturn this.getAtom(editor).update(update)\n\t}\n\n\tset(editor: Editor, state: T): T {\n\t\treturn this.getAtom(editor).set(state)\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2B;AAC3B,mBAA0B;AAYnB,MAAM,WAAc;AAAA,EAG1B,YACS,MACA,iBACP;AAFO;AACA;AAAA,EACN;AAAA,EALK,SAAS,IAAI,uBAA2B;AAAA,EAOhD,QAAQ,QAAyB;AAChC,WAAO,KAAK,OAAO,IAAI,QAAQ,UAAM,mBAAK,KAAK,MAAM,KAAK,gBAAgB,MAAM,CAAC,CAAC;AAAA,EACnF;AAAA,EAEA,IAAI,QAAmB;AACtB,WAAO,KAAK,QAAQ,MAAM,EAAE,IAAI;AAAA,EACjC;AAAA,EAEA,OAAO,QAAgB,QAA4B;AAClD,WAAO,KAAK,QAAQ,MAAM,EAAE,OAAO,MAAM;AAAA,EAC1C;AAAA,EAEA,IAAI,QAAgB,OAAa;AAChC,WAAO,KAAK,QAAQ,MAAM,EAAE,IAAI,KAAK;AAAA,EACtC;AACD;",
6
- "names": []
7
- }
@@ -1,23 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import classNames from "classnames";
3
- import { forwardRef } from "react";
4
- const DefaultShapeWrapper = forwardRef(function DefaultShapeWrapper2({ children, shape, isBackground, ...props }, ref) {
5
- const isFilledShape = "fill" in shape.props && shape.props.fill !== "none";
6
- return /* @__PURE__ */ jsx(
7
- "div",
8
- {
9
- ref,
10
- "data-shape-type": shape.type,
11
- "data-shape-is-filled": isBackground ? void 0 : isFilledShape,
12
- "data-shape-id": shape.id,
13
- draggable: false,
14
- ...props,
15
- className: classNames("tl-shape", isBackground && "tl-shape-background", props.className),
16
- children
17
- }
18
- );
19
- });
20
- export {
21
- DefaultShapeWrapper
22
- };
23
- //# sourceMappingURL=DefaultShapeWrapper.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/lib/components/default-components/DefaultShapeWrapper.tsx"],
4
- "sourcesContent": ["import { TLShape } from '@tldraw/tlschema'\nimport classNames from 'classnames'\nimport { forwardRef, ReactNode } from 'react'\n\n/** @public */\nexport interface TLShapeWrapperProps extends React.HTMLAttributes<HTMLDivElement> {\n\t/** The shape being rendered. */\n\tshape: TLShape\n\t/** Whether this is the shapes regular, or background component. */\n\tisBackground: boolean\n\t/** The shape's rendered component. */\n\tchildren: ReactNode\n}\n\n/** @public @react */\nexport const DefaultShapeWrapper = forwardRef(function DefaultShapeWrapper(\n\t{ children, shape, isBackground, ...props }: TLShapeWrapperProps,\n\tref: React.Ref<HTMLDivElement>\n) {\n\tconst isFilledShape = 'fill' in shape.props && shape.props.fill !== 'none'\n\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tdata-shape-type={shape.type}\n\t\t\tdata-shape-is-filled={isBackground ? undefined : isFilledShape}\n\t\t\tdata-shape-id={shape.id}\n\t\t\tdraggable={false}\n\t\t\t{...props}\n\t\t\tclassName={classNames('tl-shape', isBackground && 'tl-shape-background', props.className)}\n\t\t>\n\t\t\t{children}\n\t\t</div>\n\t)\n})\n"],
5
- "mappings": "AAsBE;AArBF,OAAO,gBAAgB;AACvB,SAAS,kBAA6B;AAa/B,MAAM,sBAAsB,WAAW,SAASA,qBACtD,EAAE,UAAU,OAAO,cAAc,GAAG,MAAM,GAC1C,KACC;AACD,QAAM,gBAAgB,UAAU,MAAM,SAAS,MAAM,MAAM,SAAS;AAEpE,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA,mBAAiB,MAAM;AAAA,MACvB,wBAAsB,eAAe,SAAY;AAAA,MACjD,iBAAe,MAAM;AAAA,MACrB,WAAW;AAAA,MACV,GAAG;AAAA,MACJ,WAAW,WAAW,YAAY,gBAAgB,uBAAuB,MAAM,SAAS;AAAA,MAEvF;AAAA;AAAA,EACF;AAEF,CAAC;",
6
- "names": ["DefaultShapeWrapper"]
7
- }
@@ -1,15 +0,0 @@
1
- import { react } from "@tldraw/state";
2
- import { useLayoutEffect } from "react";
3
- import { useEditor } from "./useEditor.mjs";
4
- function useStateAttribute() {
5
- const editor = useEditor();
6
- useLayoutEffect(() => {
7
- return react("stateAttribute", () => {
8
- editor.getContainer().setAttribute("data-state", editor.getPath());
9
- });
10
- }, [editor]);
11
- }
12
- export {
13
- useStateAttribute
14
- };
15
- //# sourceMappingURL=useStateAttribute.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/lib/hooks/useStateAttribute.ts"],
4
- "sourcesContent": ["import { react } from '@tldraw/state'\nimport { useLayoutEffect } from 'react'\nimport { useEditor } from './useEditor'\n\nexport function useStateAttribute() {\n\tconst editor = useEditor()\n\n\t// we use a layout effect because we don't want there to be any perceptible delay between the\n\t// editor mounting and this attribute being applied, because styles may depend on it:\n\tuseLayoutEffect(() => {\n\t\treturn react('stateAttribute', () => {\n\t\t\teditor.getContainer().setAttribute('data-state', editor.getPath())\n\t\t})\n\t}, [editor])\n}\n"],
5
- "mappings": "AAAA,SAAS,aAAa;AACtB,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;AAEnB,SAAS,oBAAoB;AACnC,QAAM,SAAS,UAAU;AAIzB,kBAAgB,MAAM;AACrB,WAAO,MAAM,kBAAkB,MAAM;AACpC,aAAO,aAAa,EAAE,aAAa,cAAc,OAAO,QAAQ,CAAC;AAAA,IAClE,CAAC;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AACZ;",
6
- "names": []
7
- }
@@ -1,25 +0,0 @@
1
- import { atom } from "@tldraw/state";
2
- import { WeakCache } from "@tldraw/utils";
3
- class EditorAtom {
4
- constructor(name, getInitialState) {
5
- this.name = name;
6
- this.getInitialState = getInitialState;
7
- }
8
- states = new WeakCache();
9
- getAtom(editor) {
10
- return this.states.get(editor, () => atom(this.name, this.getInitialState(editor)));
11
- }
12
- get(editor) {
13
- return this.getAtom(editor).get();
14
- }
15
- update(editor, update) {
16
- return this.getAtom(editor).update(update);
17
- }
18
- set(editor, state) {
19
- return this.getAtom(editor).set(state);
20
- }
21
- }
22
- export {
23
- EditorAtom
24
- };
25
- //# sourceMappingURL=EditorAtom.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/lib/utils/EditorAtom.ts"],
4
- "sourcesContent": ["import { atom, Atom } from '@tldraw/state'\nimport { WeakCache } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\n\n/**\n * An Atom that is scoped to the lifetime of an Editor.\n *\n * This is useful for storing UI state for tldraw applications. Keeping state scoped to an editor\n * instead of stored in a global atom can prevent issues with state being shared between editors\n * when navigating between pages, or when multiple editor instances are used on the same page.\n *\n * @public\n */\nexport class EditorAtom<T> {\n\tprivate states = new WeakCache<Editor, Atom<T>>()\n\n\tconstructor(\n\t\tprivate name: string,\n\t\tprivate getInitialState: (editor: Editor) => T\n\t) {}\n\n\tgetAtom(editor: Editor): Atom<T> {\n\t\treturn this.states.get(editor, () => atom(this.name, this.getInitialState(editor)))\n\t}\n\n\tget(editor: Editor): T {\n\t\treturn this.getAtom(editor).get()\n\t}\n\n\tupdate(editor: Editor, update: (state: T) => T): T {\n\t\treturn this.getAtom(editor).update(update)\n\t}\n\n\tset(editor: Editor, state: T): T {\n\t\treturn this.getAtom(editor).set(state)\n\t}\n}\n"],
5
- "mappings": "AAAA,SAAS,YAAkB;AAC3B,SAAS,iBAAiB;AAYnB,MAAM,WAAc;AAAA,EAG1B,YACS,MACA,iBACP;AAFO;AACA;AAAA,EACN;AAAA,EALK,SAAS,IAAI,UAA2B;AAAA,EAOhD,QAAQ,QAAyB;AAChC,WAAO,KAAK,OAAO,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,KAAK,gBAAgB,MAAM,CAAC,CAAC;AAAA,EACnF;AAAA,EAEA,IAAI,QAAmB;AACtB,WAAO,KAAK,QAAQ,MAAM,EAAE,IAAI;AAAA,EACjC;AAAA,EAEA,OAAO,QAAgB,QAA4B;AAClD,WAAO,KAAK,QAAQ,MAAM,EAAE,OAAO,MAAM;AAAA,EAC1C;AAAA,EAEA,IAAI,QAAgB,OAAa;AAChC,WAAO,KAAK,QAAQ,MAAM,EAAE,IAAI,KAAK;AAAA,EACtC;AACD;",
6
- "names": []
7
- }
@@ -1,35 +0,0 @@
1
- import { TLShape } from '@tldraw/tlschema'
2
- import classNames from 'classnames'
3
- import { forwardRef, ReactNode } from 'react'
4
-
5
- /** @public */
6
- export interface TLShapeWrapperProps extends React.HTMLAttributes<HTMLDivElement> {
7
- /** The shape being rendered. */
8
- shape: TLShape
9
- /** Whether this is the shapes regular, or background component. */
10
- isBackground: boolean
11
- /** The shape's rendered component. */
12
- children: ReactNode
13
- }
14
-
15
- /** @public @react */
16
- export const DefaultShapeWrapper = forwardRef(function DefaultShapeWrapper(
17
- { children, shape, isBackground, ...props }: TLShapeWrapperProps,
18
- ref: React.Ref<HTMLDivElement>
19
- ) {
20
- const isFilledShape = 'fill' in shape.props && shape.props.fill !== 'none'
21
-
22
- return (
23
- <div
24
- ref={ref}
25
- data-shape-type={shape.type}
26
- data-shape-is-filled={isBackground ? undefined : isFilledShape}
27
- data-shape-id={shape.id}
28
- draggable={false}
29
- {...props}
30
- className={classNames('tl-shape', isBackground && 'tl-shape-background', props.className)}
31
- >
32
- {children}
33
- </div>
34
- )
35
- })