@tldraw/editor 3.8.0-canary.99db1910391e → 3.8.0-canary.9b13f6b7554c

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 (46) hide show
  1. package/dist-cjs/index.d.ts +142 -46
  2. package/dist-cjs/index.js +3 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -1
  5. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  6. package/dist-cjs/lib/editor/Editor.js +25 -14
  7. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  8. package/dist-cjs/lib/editor/managers/TextManager.js +1 -0
  9. package/dist-cjs/lib/editor/managers/TextManager.js.map +2 -2
  10. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  11. package/dist-cjs/lib/editor/shapes/shared/resizeScaled.js +66 -0
  12. package/dist-cjs/lib/editor/shapes/shared/resizeScaled.js.map +7 -0
  13. package/dist-cjs/lib/editor/types/emit-types.js.map +1 -1
  14. package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
  15. package/dist-cjs/lib/options.js +2 -1
  16. package/dist-cjs/lib/options.js.map +2 -2
  17. package/dist-cjs/version.js +3 -3
  18. package/dist-cjs/version.js.map +1 -1
  19. package/dist-esm/index.d.mts +142 -46
  20. package/dist-esm/index.mjs +3 -1
  21. package/dist-esm/index.mjs.map +2 -2
  22. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +1 -1
  23. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  24. package/dist-esm/lib/editor/Editor.mjs +25 -14
  25. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  26. package/dist-esm/lib/editor/managers/TextManager.mjs +1 -0
  27. package/dist-esm/lib/editor/managers/TextManager.mjs.map +2 -2
  28. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  29. package/dist-esm/lib/editor/shapes/shared/resizeScaled.mjs +46 -0
  30. package/dist-esm/lib/editor/shapes/shared/resizeScaled.mjs.map +7 -0
  31. package/dist-esm/lib/options.mjs +2 -1
  32. package/dist-esm/lib/options.mjs.map +2 -2
  33. package/dist-esm/version.mjs +3 -3
  34. package/dist-esm/version.mjs.map +1 -1
  35. package/editor.css +2 -1
  36. package/package.json +7 -7
  37. package/src/index.ts +15 -1
  38. package/src/lib/components/default-components/DefaultCanvas.tsx +1 -1
  39. package/src/lib/editor/Editor.ts +50 -23
  40. package/src/lib/editor/managers/TextManager.ts +1 -0
  41. package/src/lib/editor/shapes/ShapeUtil.ts +30 -1
  42. package/src/lib/editor/shapes/shared/resizeScaled.ts +61 -0
  43. package/src/lib/editor/types/emit-types.ts +1 -0
  44. package/src/lib/editor/types/external-content.ts +90 -50
  45. package/src/lib/options.ts +6 -0
  46. package/src/version.ts +3 -3
@@ -0,0 +1,61 @@
1
+ import { TLBaseShape } from '@tldraw/tlschema'
2
+ import { exhaustiveSwitchError } from '@tldraw/utils'
3
+ import { Vec } from '../../../primitives/Vec'
4
+ import { TLResizeInfo } from '../ShapeUtil'
5
+
6
+ /**
7
+ * Resize a shape that has a scale prop.
8
+ *
9
+ * @param shape - The shape to resize
10
+ * @param info - The resize info
11
+ *
12
+ * @public */
13
+ export function resizeScaled(
14
+ shape: TLBaseShape<any, { scale: number }>,
15
+ { initialBounds, scaleX, scaleY, newPoint, handle }: TLResizeInfo<any>
16
+ ) {
17
+ let scaleDelta: number
18
+ switch (handle) {
19
+ case 'bottom_left':
20
+ case 'bottom_right':
21
+ case 'top_left':
22
+ case 'top_right': {
23
+ scaleDelta = Math.max(0.01, Math.max(Math.abs(scaleX), Math.abs(scaleY)))
24
+ break
25
+ }
26
+ case 'left':
27
+ case 'right': {
28
+ scaleDelta = Math.max(0.01, Math.abs(scaleX))
29
+ break
30
+ }
31
+ case 'bottom':
32
+ case 'top': {
33
+ scaleDelta = Math.max(0.01, Math.abs(scaleY))
34
+ break
35
+ }
36
+ default: {
37
+ throw exhaustiveSwitchError(handle)
38
+ }
39
+ }
40
+
41
+ // Compute the offset (if flipped X or flipped Y)
42
+ const offset = new Vec(0, 0)
43
+
44
+ if (scaleX < 0) {
45
+ offset.x = -(initialBounds.width * scaleDelta)
46
+ }
47
+ if (scaleY < 0) {
48
+ offset.y = -(initialBounds.height * scaleDelta)
49
+ }
50
+
51
+ // Apply the offset to the new point
52
+ const { x, y } = Vec.Add(newPoint, offset.rot(shape.rotation))
53
+
54
+ return {
55
+ x,
56
+ y,
57
+ props: {
58
+ scale: scaleDelta * shape.props.scale,
59
+ },
60
+ }
61
+ }
@@ -12,6 +12,7 @@ export interface TLEventMap {
12
12
  crash: [{ error: unknown }]
13
13
  'stop-camera-animation': []
14
14
  'stop-following': []
15
+ 'before-event': [TLEventInfo]
15
16
  event: [TLEventInfo]
16
17
  tick: [number]
17
18
  frame: [number]
@@ -2,57 +2,97 @@ import { TLAssetId } from '@tldraw/tlschema'
2
2
  import { VecLike } from '../../primitives/Vec'
3
3
  import { TLContent } from './clipboard-types'
4
4
 
5
+ /** @public */
6
+ export interface TLTldrawExternalContentSource {
7
+ type: 'tldraw'
8
+ data: TLContent
9
+ }
10
+
11
+ /** @public */
12
+ export interface TLExcalidrawExternalContentSource {
13
+ type: 'excalidraw'
14
+ data: any
15
+ }
16
+
17
+ /** @public */
18
+ export interface TLTextExternalContentSource {
19
+ type: 'text'
20
+ data: string
21
+ subtype: 'json' | 'html' | 'text' | 'url'
22
+ }
23
+
24
+ /** @public */
25
+ export interface TLErrorExternalContentSource {
26
+ type: 'error'
27
+ data: string | null
28
+ reason: string
29
+ }
30
+
5
31
  /** @public */
6
32
  export type TLExternalContentSource =
7
- | {
8
- type: 'tldraw'
9
- data: TLContent
10
- }
11
- | {
12
- type: 'excalidraw'
13
- data: any
14
- }
15
- | {
16
- type: 'text'
17
- data: string
18
- subtype: 'json' | 'html' | 'text' | 'url'
19
- }
20
- | {
21
- type: 'error'
22
- data: string | null
23
- reason: string
24
- }
25
-
26
- /** @public */
27
- export type TLExternalContent<EmbedDefinition> = {
33
+ | TLTldrawExternalContentSource
34
+ | TLExcalidrawExternalContentSource
35
+ | TLTextExternalContentSource
36
+ | TLErrorExternalContentSource
37
+
38
+ /** @public */
39
+ export interface TLBaseExternalContent {
28
40
  sources?: TLExternalContentSource[]
29
41
  point?: VecLike
30
- } & (
31
- | {
32
- type: 'text'
33
- text: string
34
- }
35
- | {
36
- type: 'files'
37
- files: File[]
38
- ignoreParent: boolean
39
- }
40
- | {
41
- type: 'url'
42
- url: string
43
- }
44
- | {
45
- type: 'svg-text'
46
- text: string
47
- }
48
- | {
49
- type: 'embed'
50
- url: string
51
- embed: EmbedDefinition
52
- }
53
- )
54
-
55
- /** @public */
56
- export type TLExternalAssetContent =
57
- | { type: 'file'; file: File; assetId?: TLAssetId }
58
- | { type: 'url'; url: string }
42
+ }
43
+
44
+ /** @public */
45
+ export interface TLTextExternalContent extends TLBaseExternalContent {
46
+ type: 'text'
47
+ text: string
48
+ }
49
+
50
+ /** @public */
51
+ export interface TLFilesExternalContent extends TLBaseExternalContent {
52
+ type: 'files'
53
+ files: File[]
54
+ ignoreParent: boolean
55
+ }
56
+
57
+ /** @public */
58
+ export interface TLUrlExternalContent extends TLBaseExternalContent {
59
+ type: 'url'
60
+ url: string
61
+ }
62
+
63
+ /** @public */
64
+ export interface TLSvgTextExternalContent extends TLBaseExternalContent {
65
+ type: 'svg-text'
66
+ text: string
67
+ }
68
+
69
+ /** @public */
70
+ export interface TLEmbedExternalContent<EmbedDefinition> extends TLBaseExternalContent {
71
+ type: 'embed'
72
+ url: string
73
+ embed: EmbedDefinition
74
+ }
75
+
76
+ /** @public */
77
+ export type TLExternalContent<EmbedDefinition> =
78
+ | TLTextExternalContent
79
+ | TLFilesExternalContent
80
+ | TLUrlExternalContent
81
+ | TLSvgTextExternalContent
82
+ | TLEmbedExternalContent<EmbedDefinition>
83
+
84
+ /** @public */
85
+ export interface TLFileExternalAsset {
86
+ type: 'file'
87
+ file: File
88
+ assetId?: TLAssetId
89
+ }
90
+
91
+ /** @public */
92
+ export interface TLUrlExternalAsset {
93
+ type: 'url'
94
+ url: string
95
+ }
96
+
97
+ /** @public */
98
+ export type TLExternalAsset = TLFileExternalAsset | TLUrlExternalAsset
@@ -66,6 +66,11 @@ export interface TldrawOptions {
66
66
  * external context providers. By default, this is `React.Fragment`.
67
67
  */
68
68
  readonly exportProvider: ComponentType<{ children: React.ReactNode }>
69
+ /**
70
+ * How should the note shape resize? By default it does not resize (except automatically based on its text content),
71
+ * but you can set it to be user-resizable using scale.
72
+ */
73
+ readonly noteShapeResizeMode: 'none' | 'scale'
69
74
  }
70
75
 
71
76
  /** @public */
@@ -111,4 +116,5 @@ export const defaultTldrawOptions = {
111
116
  actionShortcutsLocation: 'swap',
112
117
  createTextOnCanvasDoubleClick: true,
113
118
  exportProvider: Fragment,
119
+ noteShapeResizeMode: 'none',
114
120
  } as const satisfies TldrawOptions
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.8.0-canary.99db1910391e'
4
+ export const version = '3.8.0-canary.9b13f6b7554c'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2025-01-26T16:47:14.879Z',
8
- patch: '2025-01-26T16:47:14.879Z',
7
+ minor: '2025-01-30T10:40:54.325Z',
8
+ patch: '2025-01-30T10:40:54.325Z',
9
9
  }