tldraw 4.1.0-canary.e4499a57ef5b → 4.1.0-canary.e87046ba1a0c

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 (201) hide show
  1. package/dist-cjs/index.d.ts +46 -12
  2. package/dist-cjs/index.js +6 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/canvas/TldrawCropHandles.js +1 -1
  5. package/dist-cjs/lib/canvas/TldrawScribble.js +1 -1
  6. package/dist-cjs/lib/canvas/TldrawSelectionForeground.js +1 -1
  7. package/dist-cjs/lib/defaultEmbedDefinitions.js +25 -30
  8. package/dist-cjs/lib/defaultEmbedDefinitions.js.map +2 -2
  9. package/dist-cjs/lib/defaultExternalContentHandlers.js +10 -33
  10. package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
  11. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js +3 -0
  12. package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
  13. package/dist-cjs/lib/shapes/arrow/curved-arrow.js +8 -2
  14. package/dist-cjs/lib/shapes/arrow/curved-arrow.js.map +2 -2
  15. package/dist-cjs/lib/shapes/arrow/straight-arrow.js +4 -1
  16. package/dist-cjs/lib/shapes/arrow/straight-arrow.js.map +2 -2
  17. package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js +44 -102
  18. package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js.map +2 -2
  19. package/dist-cjs/lib/shapes/bookmark/bookmarks.js +138 -0
  20. package/dist-cjs/lib/shapes/bookmark/bookmarks.js.map +7 -0
  21. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js +25 -3
  22. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js.map +2 -2
  23. package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +1 -1
  24. package/dist-cjs/lib/shapes/image/ImageShapeUtil.js +1 -1
  25. package/dist-cjs/lib/shapes/line/LineShapeUtil.js +3 -0
  26. package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
  27. package/dist-cjs/lib/shapes/shared/HyperlinkButton.js +1 -1
  28. package/dist-cjs/lib/shapes/shared/PlainTextLabel.js +1 -1
  29. package/dist-cjs/lib/shapes/shared/RichTextLabel.js +2 -2
  30. package/dist-cjs/lib/shapes/shared/RichTextLabel.js.map +2 -2
  31. package/dist-cjs/lib/shapes/shared/ShapeFill.js +1 -1
  32. package/dist-cjs/lib/shapes/text/PlainTextArea.js +1 -1
  33. package/dist-cjs/lib/shapes/text/RichTextArea.js +1 -1
  34. package/dist-cjs/lib/shapes/video/VideoShapeUtil.js +1 -1
  35. package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/Cropping.js +20 -4
  36. package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/Cropping.js.map +2 -2
  37. package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/Idle.js +1 -1
  38. package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/Idle.js.map +2 -2
  39. package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/PointingCropHandle.js +23 -11
  40. package/dist-cjs/lib/tools/SelectTool/childStates/Crop/children/PointingCropHandle.js.map +2 -2
  41. package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js +27 -6
  42. package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js.map +2 -2
  43. package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js +1 -1
  44. package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js.map +2 -2
  45. package/dist-cjs/lib/tools/SelectTool/childStates/PointingArrowLabel.js +21 -9
  46. package/dist-cjs/lib/tools/SelectTool/childStates/PointingArrowLabel.js.map +2 -2
  47. package/dist-cjs/lib/tools/SelectTool/childStates/PointingResizeHandle.js +24 -8
  48. package/dist-cjs/lib/tools/SelectTool/childStates/PointingResizeHandle.js.map +2 -2
  49. package/dist-cjs/lib/tools/SelectTool/childStates/PointingRotateHandle.js +21 -9
  50. package/dist-cjs/lib/tools/SelectTool/childStates/PointingRotateHandle.js.map +2 -2
  51. package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js +23 -8
  52. package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js.map +2 -2
  53. package/dist-cjs/lib/tools/SelectTool/childStates/Rotating.js +21 -9
  54. package/dist-cjs/lib/tools/SelectTool/childStates/Rotating.js.map +2 -2
  55. package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js +26 -11
  56. package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
  57. package/dist-cjs/lib/ui/TldrawUi.js +2 -2
  58. package/dist-cjs/lib/ui/components/DebugMenu/DefaultDebugMenuContent.js +1 -1
  59. package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialog.js +1 -1
  60. package/dist-cjs/lib/ui/components/Minimap/DefaultMinimap.js +1 -1
  61. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js +5 -0
  62. package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js.map +2 -2
  63. package/dist-cjs/lib/ui/components/OfflineIndicator/OfflineIndicator.js +1 -1
  64. package/dist-cjs/lib/ui/components/SharePanel/PeopleMenu.js +6 -2
  65. package/dist-cjs/lib/ui/components/SharePanel/PeopleMenu.js.map +2 -2
  66. package/dist-cjs/lib/ui/components/SharePanel/UserPresenceColorPicker.js +1 -1
  67. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanel.js +1 -1
  68. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js +64 -56
  69. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js.map +2 -2
  70. package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js +54 -47
  71. package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js.map +3 -3
  72. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.js +63 -56
  73. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.js.map +2 -2
  74. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDropdownPicker.js +13 -6
  75. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDropdownPicker.js.map +2 -2
  76. package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js +1 -1
  77. package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js +1 -1
  78. package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js +1 -1
  79. package/dist-cjs/lib/ui/components/primitives/Button/TldrawUiButton.js +2 -2
  80. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js +1 -1
  81. package/dist-cjs/lib/ui/components/primitives/TldrawUiDialog.js +1 -1
  82. package/dist-cjs/lib/ui/components/primitives/TldrawUiDropdownMenu.js +1 -1
  83. package/dist-cjs/lib/ui/components/primitives/TldrawUiIcon.js +1 -1
  84. package/dist-cjs/lib/ui/components/primitives/TldrawUiInput.js +2 -2
  85. package/dist-cjs/lib/ui/components/primitives/TldrawUiPopover.js +2 -2
  86. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +1 -1
  87. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js +2 -2
  88. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +1 -1
  89. package/dist-cjs/lib/ui/components/primitives/layout.js +1 -1
  90. package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js +1 -1
  91. package/dist-cjs/lib/ui/context/actions.js +24 -30
  92. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  93. package/dist-cjs/lib/ui/context/breakpoints.js +1 -1
  94. package/dist-cjs/lib/ui/context/events.js +1 -1
  95. package/dist-cjs/lib/ui/hooks/useClipboardEvents.js +1 -1
  96. package/dist-cjs/lib/ui/hooks/useKeyboardShortcuts.js +1 -1
  97. package/dist-cjs/lib/ui/hooks/useLocalStorageState.js +1 -1
  98. package/dist-cjs/lib/ui/hooks/useTools.js +1 -1
  99. package/dist-cjs/lib/ui/hooks/useTranslation/useTranslation.js +1 -1
  100. package/dist-cjs/lib/ui/version.js +3 -3
  101. package/dist-cjs/lib/ui/version.js.map +1 -1
  102. package/dist-cjs/lib/utils/text/richText.js +4 -4
  103. package/dist-esm/index.d.mts +46 -12
  104. package/dist-esm/index.mjs +12 -4
  105. package/dist-esm/index.mjs.map +2 -2
  106. package/dist-esm/lib/defaultEmbedDefinitions.mjs +25 -30
  107. package/dist-esm/lib/defaultEmbedDefinitions.mjs.map +2 -2
  108. package/dist-esm/lib/defaultExternalContentHandlers.mjs +10 -33
  109. package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
  110. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +3 -0
  111. package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
  112. package/dist-esm/lib/shapes/arrow/curved-arrow.mjs +8 -2
  113. package/dist-esm/lib/shapes/arrow/curved-arrow.mjs.map +2 -2
  114. package/dist-esm/lib/shapes/arrow/straight-arrow.mjs +4 -1
  115. package/dist-esm/lib/shapes/arrow/straight-arrow.mjs.map +2 -2
  116. package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs +46 -101
  117. package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs.map +2 -2
  118. package/dist-esm/lib/shapes/bookmark/bookmarks.mjs +124 -0
  119. package/dist-esm/lib/shapes/bookmark/bookmarks.mjs.map +7 -0
  120. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs +26 -3
  121. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs.map +2 -2
  122. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +3 -0
  123. package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
  124. package/dist-esm/lib/shapes/shared/RichTextLabel.mjs +1 -1
  125. package/dist-esm/lib/shapes/shared/RichTextLabel.mjs.map +2 -2
  126. package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/Cropping.mjs +20 -4
  127. package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/Cropping.mjs.map +2 -2
  128. package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/Idle.mjs +1 -1
  129. package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/Idle.mjs.map +2 -2
  130. package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/PointingCropHandle.mjs +23 -11
  131. package/dist-esm/lib/tools/SelectTool/childStates/Crop/children/PointingCropHandle.mjs.map +2 -2
  132. package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs +29 -7
  133. package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs.map +2 -2
  134. package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs +1 -1
  135. package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs.map +2 -2
  136. package/dist-esm/lib/tools/SelectTool/childStates/PointingArrowLabel.mjs +21 -9
  137. package/dist-esm/lib/tools/SelectTool/childStates/PointingArrowLabel.mjs.map +2 -2
  138. package/dist-esm/lib/tools/SelectTool/childStates/PointingResizeHandle.mjs +24 -8
  139. package/dist-esm/lib/tools/SelectTool/childStates/PointingResizeHandle.mjs.map +2 -2
  140. package/dist-esm/lib/tools/SelectTool/childStates/PointingRotateHandle.mjs +21 -9
  141. package/dist-esm/lib/tools/SelectTool/childStates/PointingRotateHandle.mjs.map +2 -2
  142. package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs +23 -8
  143. package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs.map +2 -2
  144. package/dist-esm/lib/tools/SelectTool/childStates/Rotating.mjs +21 -9
  145. package/dist-esm/lib/tools/SelectTool/childStates/Rotating.mjs.map +2 -2
  146. package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs +26 -11
  147. package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
  148. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs +5 -0
  149. package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs.map +2 -2
  150. package/dist-esm/lib/ui/components/SharePanel/PeopleMenu.mjs +6 -2
  151. package/dist-esm/lib/ui/components/SharePanel/PeopleMenu.mjs.map +2 -2
  152. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs +68 -57
  153. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs.map +2 -2
  154. package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs +54 -47
  155. package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs.map +3 -3
  156. package/dist-esm/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.mjs +63 -56
  157. package/dist-esm/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.mjs.map +2 -2
  158. package/dist-esm/lib/ui/components/StylePanel/StylePanelDropdownPicker.mjs +12 -5
  159. package/dist-esm/lib/ui/components/StylePanel/StylePanelDropdownPicker.mjs.map +2 -2
  160. package/dist-esm/lib/ui/context/actions.mjs +23 -29
  161. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  162. package/dist-esm/lib/ui/version.mjs +3 -3
  163. package/dist-esm/lib/ui/version.mjs.map +1 -1
  164. package/package.json +11 -11
  165. package/src/index.ts +4 -0
  166. package/src/lib/defaultEmbedDefinitions.ts +20 -24
  167. package/src/lib/defaultExternalContentHandlers.ts +12 -37
  168. package/src/lib/shapes/arrow/ArrowShapeUtil.test.ts +211 -1
  169. package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +3 -0
  170. package/src/lib/shapes/arrow/curved-arrow.ts +8 -2
  171. package/src/lib/shapes/arrow/straight-arrow.ts +5 -1
  172. package/src/lib/shapes/bookmark/BookmarkShapeUtil.tsx +51 -135
  173. package/src/lib/shapes/bookmark/bookmarks.ts +170 -0
  174. package/src/lib/shapes/embed/EmbedShapeUtil.tsx +28 -2
  175. package/src/lib/shapes/line/LineShapeUtil.tsx +3 -0
  176. package/src/lib/shapes/shared/RichTextLabel.tsx +1 -1
  177. package/src/lib/shapes/text/TextShapeTool.test.ts +74 -0
  178. package/src/lib/tools/SelectTool/childStates/Crop/children/Cropping.ts +23 -6
  179. package/src/lib/tools/SelectTool/childStates/Crop/children/Idle.ts +1 -1
  180. package/src/lib/tools/SelectTool/childStates/Crop/children/PointingCropHandle.ts +24 -12
  181. package/src/lib/tools/SelectTool/childStates/DraggingHandle.tsx +34 -11
  182. package/src/lib/tools/SelectTool/childStates/Idle.ts +1 -1
  183. package/src/lib/tools/SelectTool/childStates/PointingArrowLabel.ts +23 -11
  184. package/src/lib/tools/SelectTool/childStates/PointingResizeHandle.ts +26 -9
  185. package/src/lib/tools/SelectTool/childStates/PointingRotateHandle.ts +23 -10
  186. package/src/lib/tools/SelectTool/childStates/Resizing.ts +24 -9
  187. package/src/lib/tools/SelectTool/childStates/Rotating.ts +27 -11
  188. package/src/lib/tools/SelectTool/childStates/Translating.ts +28 -12
  189. package/src/lib/ui/components/Minimap/MinimapManager.ts +6 -0
  190. package/src/lib/ui/components/SharePanel/PeopleMenu.tsx +6 -2
  191. package/src/lib/ui/components/StylePanel/DefaultStylePanelContent.tsx +60 -49
  192. package/src/lib/ui/components/StylePanel/StylePanelButtonPicker.tsx +70 -53
  193. package/src/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.tsx +105 -90
  194. package/src/lib/ui/components/StylePanel/StylePanelDropdownPicker.tsx +72 -51
  195. package/src/lib/ui/context/actions.tsx +27 -31
  196. package/src/lib/ui/version.ts +3 -3
  197. package/src/lib/utils/embeds/embeds.test.ts +16 -34
  198. package/src/test/SelectTool.test.ts +251 -0
  199. package/src/test/bookmark-shapes.test.ts +129 -7
  200. package/src/test/customSnapping.test.tsx +55 -11
  201. package/tldraw.css +7 -2
@@ -1,7 +1,5 @@
1
1
  import {
2
- AssetRecordType,
3
2
  BaseBoxShapeUtil,
4
- Editor,
5
3
  HTMLContainer,
6
4
  T,
7
5
  TLAssetId,
@@ -10,8 +8,6 @@ import {
10
8
  TLBookmarkShapeProps,
11
9
  bookmarkShapeMigrations,
12
10
  bookmarkShapeProps,
13
- debounce,
14
- getHashForString,
15
11
  lerp,
16
12
  tlenv,
17
13
  toDomPrecision,
@@ -24,11 +20,13 @@ import { convertCommonTitleHTMLEntities } from '../../utils/text/text'
24
20
  import { HyperlinkButton } from '../shared/HyperlinkButton'
25
21
  import { LINK_ICON } from '../shared/icons-editor'
26
22
  import { getRotatedBoxShadow } from '../shared/rotated-box-shadow'
27
-
28
- const BOOKMARK_WIDTH = 300
29
- const BOOKMARK_HEIGHT = 320
30
- const BOOKMARK_JUST_URL_HEIGHT = 46
31
- const SHORT_BOOKMARK_HEIGHT = 101
23
+ import {
24
+ BOOKMARK_HEIGHT,
25
+ BOOKMARK_WIDTH,
26
+ getHumanReadableAddress,
27
+ setBookmarkHeight,
28
+ updateBookmarkAssetOnUrlChange,
29
+ } from './bookmarks'
32
30
 
33
31
  /** @public */
34
32
  export class BookmarkShapeUtil extends BaseBoxShapeUtil<TLBookmarkShape> {
@@ -71,22 +69,18 @@ export class BookmarkShapeUtil extends BaseBoxShapeUtil<TLBookmarkShape> {
71
69
  }
72
70
 
73
71
  override component(shape: TLBookmarkShape) {
74
- return <BookmarkShapeComponent shape={shape} />
72
+ const { assetId, url, h } = shape.props
73
+ const rotation = this.editor.getShapePageTransform(shape)!.rotation()
74
+
75
+ return <BookmarkShapeComponent assetId={assetId} url={url} h={h} rotation={rotation} />
75
76
  }
76
77
 
77
78
  override indicator(shape: TLBookmarkShape) {
78
- return (
79
- <rect
80
- width={toDomPrecision(shape.props.w)}
81
- height={toDomPrecision(shape.props.h)}
82
- rx="6"
83
- ry="6"
84
- />
85
- )
79
+ return <BookmarkIndicatorComponent w={shape.props.w} h={shape.props.h} />
86
80
  }
87
81
 
88
82
  override onBeforeCreate(next: TLBookmarkShape) {
89
- return getBookmarkSize(this.editor, next)
83
+ return setBookmarkHeight(this.editor, next)
90
84
  }
91
85
 
92
86
  override onBeforeUpdate(prev: TLBookmarkShape, shape: TLBookmarkShape) {
@@ -99,7 +93,7 @@ export class BookmarkShapeUtil extends BaseBoxShapeUtil<TLBookmarkShape> {
99
93
  }
100
94
 
101
95
  if (prev.props.assetId !== shape.props.assetId) {
102
- return getBookmarkSize(this.editor, shape)
96
+ return setBookmarkHeight(this.editor, shape)
103
97
  }
104
98
  }
105
99
  override getInterpolatedProps(
@@ -115,18 +109,30 @@ export class BookmarkShapeUtil extends BaseBoxShapeUtil<TLBookmarkShape> {
115
109
  }
116
110
  }
117
111
 
118
- function BookmarkShapeComponent({ shape }: { shape: TLBookmarkShape }) {
112
+ export function BookmarkIndicatorComponent({ w, h }: { w: number; h: number }) {
113
+ return <rect width={toDomPrecision(w)} height={toDomPrecision(h)} rx="6" ry="6" />
114
+ }
115
+
116
+ export function BookmarkShapeComponent({
117
+ assetId,
118
+ rotation,
119
+ url,
120
+ h,
121
+ showImageContainer = true,
122
+ }: {
123
+ assetId: TLAssetId | null
124
+ rotation: number
125
+ h: number
126
+ url: string
127
+ showImageContainer?: boolean
128
+ }) {
119
129
  const editor = useEditor()
120
130
 
121
- const asset = (
122
- shape.props.assetId ? editor.getAsset(shape.props.assetId) : null
123
- ) as TLBookmarkAsset
131
+ const asset = assetId ? (editor.getAsset(assetId) as TLBookmarkAsset) : null
124
132
 
125
133
  const isSafariExport = !!useSvgExportContext() && tlenv.isSafari
126
134
 
127
- const pageRotation = editor.getShapePageTransform(shape)!.rotation()
128
-
129
- const address = getHumanReadableAddress(shape)
135
+ const address = getHumanReadableAddress(url)
130
136
 
131
137
  const [isFaviconValid, setIsFaviconValid] = useState(true)
132
138
  const onFaviconError = () => setIsFaviconValid(false)
@@ -146,11 +152,11 @@ function BookmarkShapeComponent({ shape }: { shape: TLBookmarkShape }) {
146
152
  isSafariExport && 'tl-bookmark__container--safariExport'
147
153
  )}
148
154
  style={{
149
- boxShadow: isSafariExport ? undefined : getRotatedBoxShadow(pageRotation),
150
- maxHeight: shape.props.h,
155
+ boxShadow: isSafariExport ? undefined : getRotatedBoxShadow(rotation),
156
+ maxHeight: h,
151
157
  }}
152
158
  >
153
- {(!asset || asset.props.image) && (
159
+ {showImageContainer && (!asset || asset.props.image) && (
154
160
  <div className="tl-bookmark__image_container">
155
161
  {asset ? (
156
162
  <img
@@ -163,21 +169,31 @@ function BookmarkShapeComponent({ shape }: { shape: TLBookmarkShape }) {
163
169
  ) : (
164
170
  <div className="tl-bookmark__placeholder" />
165
171
  )}
166
- {asset?.props.image && <HyperlinkButton url={shape.props.url} />}
172
+ {asset?.props.image && <HyperlinkButton url={url} />}
167
173
  </div>
168
174
  )}
169
175
  <div className="tl-bookmark__copy_container">
170
176
  {asset?.props.title ? (
171
- <h2 className="tl-bookmark__heading">
172
- {convertCommonTitleHTMLEntities(asset.props.title)}
173
- </h2>
177
+ <a
178
+ className="tl-bookmark__link"
179
+ href={url || ''}
180
+ target="_blank"
181
+ rel="noopener noreferrer"
182
+ draggable={false}
183
+ onPointerDown={markAsHandledOnShiftKey}
184
+ onPointerUp={markAsHandledOnShiftKey}
185
+ >
186
+ <h2 className="tl-bookmark__heading">
187
+ {convertCommonTitleHTMLEntities(asset.props.title)}
188
+ </h2>
189
+ </a>
174
190
  ) : null}
175
191
  {asset?.props.description && asset?.props.image ? (
176
192
  <p className="tl-bookmark__description">{asset.props.description}</p>
177
193
  ) : null}
178
194
  <a
179
195
  className="tl-bookmark__link"
180
- href={shape.props.url || ''}
196
+ href={url || ''}
181
197
  target="_blank"
182
198
  rel="noopener noreferrer"
183
199
  draggable={false}
@@ -208,103 +224,3 @@ function BookmarkShapeComponent({ shape }: { shape: TLBookmarkShape }) {
208
224
  </HTMLContainer>
209
225
  )
210
226
  }
211
-
212
- function getBookmarkSize(editor: Editor, shape: TLBookmarkShape) {
213
- const asset = (
214
- shape.props.assetId ? editor.getAsset(shape.props.assetId) : null
215
- ) as TLBookmarkAsset
216
-
217
- let h = BOOKMARK_HEIGHT
218
-
219
- if (asset) {
220
- if (!asset.props.image) {
221
- if (!asset.props.title) {
222
- h = BOOKMARK_JUST_URL_HEIGHT
223
- } else {
224
- h = SHORT_BOOKMARK_HEIGHT
225
- }
226
- }
227
- }
228
-
229
- return {
230
- ...shape,
231
- props: {
232
- ...shape.props,
233
- h,
234
- },
235
- }
236
- }
237
-
238
- /** @internal */
239
- export const getHumanReadableAddress = (shape: TLBookmarkShape) => {
240
- try {
241
- const url = new URL(shape.props.url)
242
- // we want the hostname without any www
243
- return url.hostname.replace(/^www\./, '')
244
- } catch {
245
- return shape.props.url
246
- }
247
- }
248
-
249
- function updateBookmarkAssetOnUrlChange(editor: Editor, shape: TLBookmarkShape) {
250
- const { url } = shape.props
251
-
252
- // Derive the asset id from the URL
253
- const assetId: TLAssetId = AssetRecordType.createId(getHashForString(url))
254
-
255
- if (editor.getAsset(assetId)) {
256
- // Existing asset for this URL?
257
- if (shape.props.assetId !== assetId) {
258
- editor.updateShapes<TLBookmarkShape>([
259
- {
260
- id: shape.id,
261
- type: shape.type,
262
- props: { assetId },
263
- },
264
- ])
265
- }
266
- } else {
267
- // No asset for this URL?
268
-
269
- // First, clear out the existing asset reference
270
- editor.updateShapes<TLBookmarkShape>([
271
- {
272
- id: shape.id,
273
- type: shape.type,
274
- props: { assetId: null },
275
- },
276
- ])
277
-
278
- // Then try to asyncronously create a new one
279
- createBookmarkAssetOnUrlChange(editor, shape)
280
- }
281
- }
282
-
283
- const createBookmarkAssetOnUrlChange = debounce(async (editor: Editor, shape: TLBookmarkShape) => {
284
- if (editor.isDisposed) return
285
-
286
- const { url } = shape.props
287
-
288
- // Create the asset using the external content manager's createAssetFromUrl method.
289
- // This may be overwritten by the user (for example, we overwrite it on tldraw.com)
290
- const asset = await editor.getAssetForExternalContent({ type: 'url', url })
291
-
292
- if (!asset) {
293
- // No asset? Just leave the bookmark as a null assetId.
294
- return
295
- }
296
-
297
- editor.run(() => {
298
- // Create the new asset
299
- editor.createAssets([asset])
300
-
301
- // And update the shape
302
- editor.updateShapes<TLBookmarkShape>([
303
- {
304
- id: shape.id,
305
- type: shape.type,
306
- props: { assetId: asset.id },
307
- },
308
- ])
309
- })
310
- }, 500)
@@ -0,0 +1,170 @@
1
+ import {
2
+ AssetRecordType,
3
+ Editor,
4
+ Result,
5
+ TLAssetId,
6
+ TLBookmarkAsset,
7
+ TLBookmarkShape,
8
+ TLShapePartial,
9
+ createShapeId,
10
+ debounce,
11
+ getHashForString,
12
+ } from '@tldraw/editor'
13
+
14
+ export const BOOKMARK_WIDTH = 300
15
+ export const BOOKMARK_HEIGHT = 320
16
+ export const BOOKMARK_JUST_URL_HEIGHT = 46
17
+ const SHORT_BOOKMARK_HEIGHT = 101
18
+
19
+ export function getBookmarkHeight(editor: Editor, assetId?: TLAssetId | null) {
20
+ const asset = (assetId ? editor.getAsset(assetId) : null) as TLBookmarkAsset | null
21
+
22
+ if (asset) {
23
+ if (!asset.props.image) {
24
+ if (!asset.props.title) {
25
+ return BOOKMARK_JUST_URL_HEIGHT
26
+ } else {
27
+ return SHORT_BOOKMARK_HEIGHT
28
+ }
29
+ }
30
+ }
31
+
32
+ return BOOKMARK_HEIGHT
33
+ }
34
+
35
+ export function setBookmarkHeight(editor: Editor, shape: TLBookmarkShape) {
36
+ return {
37
+ ...shape,
38
+ props: { ...shape.props, h: getBookmarkHeight(editor, shape.props.assetId) },
39
+ }
40
+ }
41
+
42
+ /** @internal */
43
+ export const getHumanReadableAddress = (url: string) => {
44
+ try {
45
+ const objUrl = new URL(url)
46
+ // we want the hostname without any www
47
+ return objUrl.hostname.replace(/^www\./, '')
48
+ } catch {
49
+ return url
50
+ }
51
+ }
52
+
53
+ export function updateBookmarkAssetOnUrlChange(editor: Editor, shape: TLBookmarkShape) {
54
+ const { url } = shape.props
55
+
56
+ // Derive the asset id from the URL
57
+ const assetId: TLAssetId = AssetRecordType.createId(getHashForString(url))
58
+
59
+ if (editor.getAsset(assetId)) {
60
+ // Existing asset for this URL?
61
+ if (shape.props.assetId !== assetId) {
62
+ editor.updateShapes<TLBookmarkShape>([
63
+ {
64
+ id: shape.id,
65
+ type: shape.type,
66
+ props: { assetId },
67
+ },
68
+ ])
69
+ }
70
+ } else {
71
+ // No asset for this URL?
72
+
73
+ // First, clear out the existing asset reference
74
+ editor.updateShapes<TLBookmarkShape>([
75
+ {
76
+ id: shape.id,
77
+ type: shape.type,
78
+ props: { assetId: null },
79
+ },
80
+ ])
81
+
82
+ // Then try to asyncronously create a new one
83
+ createBookmarkAssetOnUrlChange(editor, shape)
84
+ }
85
+ }
86
+
87
+ const createBookmarkAssetOnUrlChange = debounce(async (editor: Editor, shape: TLBookmarkShape) => {
88
+ if (editor.isDisposed) return
89
+
90
+ const { url } = shape.props
91
+
92
+ // Create the asset using the external content manager's createAssetFromUrl method.
93
+ // This may be overwritten by the user (for example, we overwrite it on tldraw.com)
94
+ const asset = await editor.getAssetForExternalContent({ type: 'url', url })
95
+
96
+ if (!asset) {
97
+ // No asset? Just leave the bookmark as a null assetId.
98
+ return
99
+ }
100
+
101
+ editor.run(() => {
102
+ // Create the new asset
103
+ editor.createAssets([asset])
104
+
105
+ // And update the shape
106
+ editor.updateShapes<TLBookmarkShape>([
107
+ {
108
+ id: shape.id,
109
+ type: shape.type,
110
+ props: { assetId: asset.id },
111
+ },
112
+ ])
113
+ })
114
+ }, 500)
115
+
116
+ /**
117
+ * Creates a bookmark shape from a URL with unfurled metadata.
118
+ *
119
+ * @returns A Result containing the created bookmark shape or an error
120
+ * @public
121
+ */
122
+
123
+ export async function createBookmarkFromUrl(
124
+ editor: Editor,
125
+ {
126
+ url,
127
+ center = editor.getViewportPageBounds().center,
128
+ }: {
129
+ url: string
130
+ center?: { x: number; y: number }
131
+ }
132
+ ): Promise<Result<TLBookmarkShape, string>> {
133
+ try {
134
+ // Create the bookmark asset with unfurled metadata
135
+ const asset = await editor.getAssetForExternalContent({ type: 'url', url })
136
+
137
+ // Create the bookmark shape
138
+ const shapeId = createShapeId()
139
+ const shapePartial: TLShapePartial<TLBookmarkShape> = {
140
+ id: shapeId,
141
+ type: 'bookmark',
142
+ x: center.x - BOOKMARK_WIDTH / 2,
143
+ y: center.y - BOOKMARK_HEIGHT / 2,
144
+ rotation: 0,
145
+ opacity: 1,
146
+ props: {
147
+ url,
148
+ assetId: asset?.id || null,
149
+ w: BOOKMARK_WIDTH,
150
+ h: getBookmarkHeight(editor, asset?.id),
151
+ },
152
+ }
153
+
154
+ editor.run(() => {
155
+ // Create the asset if we have one
156
+ if (asset) {
157
+ editor.createAssets([asset])
158
+ }
159
+
160
+ // Create the shape
161
+ editor.createShapes([shapePartial])
162
+ })
163
+
164
+ // Get the created shape
165
+ const createdShape = editor.getShape(shapeId) as TLBookmarkShape
166
+ return Result.ok(createdShape)
167
+ } catch (error) {
168
+ return Result.err(error instanceof Error ? error.message : 'Failed to create bookmark')
169
+ }
170
+ }
@@ -3,6 +3,7 @@
3
3
  import {
4
4
  BaseBoxShapeUtil,
5
5
  HTMLContainer,
6
+ Rectangle2d,
6
7
  TLEmbedShape,
7
8
  TLEmbedShapeProps,
8
9
  TLResizeInfo,
@@ -24,6 +25,8 @@ import {
24
25
  embedShapePermissionDefaults,
25
26
  } from '../../defaultEmbedDefinitions'
26
27
  import { TLEmbedResult, getEmbedInfo } from '../../utils/embeds/embeds'
28
+ import { BookmarkIndicatorComponent, BookmarkShapeComponent } from '../bookmark/BookmarkShapeUtil'
29
+ import { BOOKMARK_JUST_URL_HEIGHT, BOOKMARK_WIDTH } from '../bookmark/bookmarks'
27
30
  import { getRotatedBoxShadow } from '../shared/rotated-box-shadow'
28
31
 
29
32
  const getSandboxPermissions = (permissions: TLEmbedShapePermissions) => {
@@ -82,6 +85,18 @@ export class EmbedShapeUtil extends BaseBoxShapeUtil<TLEmbedShape> {
82
85
  }
83
86
  }
84
87
 
88
+ override getGeometry(shape: TLEmbedShape) {
89
+ const embedInfo = this.getEmbedDefinition(shape.props.url)
90
+ if (!embedInfo?.definition) {
91
+ return new Rectangle2d({
92
+ width: BOOKMARK_WIDTH,
93
+ height: BOOKMARK_JUST_URL_HEIGHT,
94
+ isFilled: true,
95
+ })
96
+ }
97
+ return super.getGeometry(shape)
98
+ }
99
+
85
100
  override isAspectRatioLocked(shape: TLEmbedShape) {
86
101
  const embedInfo = this.getEmbedDefinition(shape.props.url)
87
102
  return embedInfo?.definition.isAspectRatioLocked ?? false
@@ -206,20 +221,31 @@ export class EmbedShapeUtil extends BaseBoxShapeUtil<TLEmbedShape> {
206
221
  background: embedInfo?.definition.backgroundColor,
207
222
  }}
208
223
  />
209
- ) : null}
224
+ ) : (
225
+ <BookmarkShapeComponent
226
+ url={url}
227
+ h={h}
228
+ rotation={pageRotation}
229
+ assetId={null}
230
+ showImageContainer={false}
231
+ />
232
+ )}
210
233
  </HTMLContainer>
211
234
  )
212
235
  }
213
236
 
214
237
  override indicator(shape: TLEmbedShape) {
215
238
  const embedInfo = this.getEmbedDefinition(shape.props.url)
216
- return (
239
+
240
+ return embedInfo?.definition ? (
217
241
  <rect
218
242
  width={toDomPrecision(shape.props.w)}
219
243
  height={toDomPrecision(shape.props.h)}
220
244
  rx={embedInfo?.definition.overrideOutlineRadius ?? 8}
221
245
  ry={embedInfo?.definition.overrideOutlineRadius ?? 8}
222
246
  />
247
+ ) : (
248
+ <BookmarkIndicatorComponent w={BOOKMARK_WIDTH} h={BOOKMARK_JUST_URL_HEIGHT} />
223
249
  )
224
250
  }
225
251
  override getInterpolatedProps(
@@ -48,6 +48,9 @@ export class LineShapeUtil extends ShapeUtil<TLLineShape> {
48
48
  override hideSelectionBoundsBg() {
49
49
  return true
50
50
  }
51
+ override hideInMinimap() {
52
+ return true
53
+ }
51
54
 
52
55
  override getDefaultProps(): TLLineShape['props'] {
53
56
  const [start, end] = getIndices(2)
@@ -109,7 +109,7 @@ export const RichTextLabel = React.memo(function RichTextLabel({
109
109
  // We don't get the mouseup event later because we preventDefault
110
110
  // so we have to do it manually.
111
111
  const handlePointerUp = (e: TLEventInfo) => {
112
- if (e.name !== 'pointer_up') return
112
+ if (e.name !== 'pointer_up' || !link) return
113
113
 
114
114
  if (!isDragging.current) {
115
115
  window.open(link, '_blank', 'noopener, noreferrer')
@@ -86,6 +86,80 @@ describe('When in idle state', () => {
86
86
  editor.cancel()
87
87
  editor.expectToBeIn('select.idle')
88
88
  })
89
+
90
+ it('starts editing selected text shape on Enter key', () => {
91
+ // Create a text shape using the same method as other tests
92
+ expect(editor.getCurrentPageShapes().length).toBe(0)
93
+ editor.setCurrentTool('text')
94
+ editor.pointerDown(0, 0)
95
+ editor.pointerUp()
96
+ editor.expectToBeIn('select.editing_shape')
97
+
98
+ // Update the text shape with some content
99
+ editor.updateShapes<TLTextShape>([
100
+ {
101
+ ...editor.getCurrentPageShapes()[0]!,
102
+ type: 'text',
103
+ props: { richText: toRichText('Hello') },
104
+ },
105
+ ])
106
+
107
+ // Exit editing mode
108
+ editor.cancel()
109
+ editor.expectToBeIn('select.idle')
110
+
111
+ // Verify the text shape exists and is selected
112
+ expect(editor.getCurrentPageShapes().length).toBe(1)
113
+ const textShape = editor.getCurrentPageShapes()[0]
114
+ expect(textShape.type).toBe('text')
115
+ editor.setSelectedShapes([textShape])
116
+
117
+ // Switch to text tool and press Enter
118
+ editor.setCurrentTool('text')
119
+ editor.expectToBeIn('text.idle')
120
+ editor.keyDown('Enter')
121
+
122
+ // Should transition to editing the selected text shape
123
+ editor.expectToBeIn('select.editing_shape')
124
+ expect(editor.getEditingShapeId()).toBe(textShape.id)
125
+ })
126
+
127
+ it('starts editing selected text shape on numpad Enter key', () => {
128
+ // Create a text shape using the same method as other tests
129
+ expect(editor.getCurrentPageShapes().length).toBe(0)
130
+ editor.setCurrentTool('text')
131
+ editor.pointerDown(0, 0)
132
+ editor.pointerUp()
133
+ editor.expectToBeIn('select.editing_shape')
134
+
135
+ // Update the text shape with some content
136
+ editor.updateShapes<TLTextShape>([
137
+ {
138
+ ...editor.getCurrentPageShapes()[0]!,
139
+ type: 'text',
140
+ props: { richText: toRichText('Hello') },
141
+ },
142
+ ])
143
+
144
+ // Exit editing mode
145
+ editor.cancel()
146
+ editor.expectToBeIn('select.idle')
147
+
148
+ // Verify the text shape exists and is selected
149
+ expect(editor.getCurrentPageShapes().length).toBe(1)
150
+ const textShape = editor.getCurrentPageShapes()[0]
151
+ expect(textShape.type).toBe('text')
152
+ editor.setSelectedShapes([textShape])
153
+
154
+ // Switch to text tool and press numpad Enter
155
+ editor.setCurrentTool('text')
156
+ editor.expectToBeIn('text.idle')
157
+ editor.keyDown('Enter', { code: 'NumpadEnter' })
158
+
159
+ // Should transition to editing the selected text shape
160
+ editor.expectToBeIn('select.editing_shape')
161
+ expect(editor.getEditingShapeId()).toBe(textShape.id)
162
+ })
89
163
  })
90
164
 
91
165
  describe('When in the pointing state', () => {
@@ -17,7 +17,7 @@ export class Cropping extends StateNode {
17
17
  info = {} as TLPointerEventInfo & {
18
18
  target: 'selection'
19
19
  handle: SelectionHandle
20
- onInteractionEnd?: string
20
+ onInteractionEnd?: string | (() => void)
21
21
  }
22
22
 
23
23
  markId = ''
@@ -28,10 +28,13 @@ export class Cropping extends StateNode {
28
28
  info: TLPointerEventInfo & {
29
29
  target: 'selection'
30
30
  handle: SelectionHandle
31
- onInteractionEnd?: string
31
+ onInteractionEnd?: string | (() => void)
32
32
  }
33
33
  ) {
34
34
  this.info = info
35
+ if (typeof info.onInteractionEnd === 'string') {
36
+ this.parent.setCurrentToolIdMask(info.onInteractionEnd)
37
+ }
35
38
  this.markId = this.editor.markHistoryStoppingPoint('cropping')
36
39
  this.snapshot = this.createSnapshot()
37
40
  this.updateShapes()
@@ -61,6 +64,10 @@ export class Cropping extends StateNode {
61
64
  this.cancel()
62
65
  }
63
66
 
67
+ override onExit() {
68
+ this.parent.setCurrentToolIdMask(undefined)
69
+ }
70
+
64
71
  private updateCursor() {
65
72
  const selectedShape = this.editor.getSelectedShapes()[0]
66
73
  if (!selectedShape) return
@@ -108,8 +115,13 @@ export class Cropping extends StateNode {
108
115
  private complete() {
109
116
  this.updateShapes()
110
117
  kickoutOccludedShapes(this.editor, [this.snapshot.shape.id])
111
- if (this.info.onInteractionEnd) {
112
- this.editor.setCurrentTool(this.info.onInteractionEnd, this.info)
118
+ const { onInteractionEnd } = this.info
119
+ if (onInteractionEnd) {
120
+ if (typeof onInteractionEnd === 'string') {
121
+ this.editor.setCurrentTool(onInteractionEnd, this.info)
122
+ } else {
123
+ onInteractionEnd()
124
+ }
113
125
  } else {
114
126
  this.editor.setCroppingShape(null)
115
127
  this.editor.setCurrentTool('select.idle')
@@ -118,8 +130,13 @@ export class Cropping extends StateNode {
118
130
 
119
131
  private cancel() {
120
132
  this.editor.bailToMark(this.markId)
121
- if (this.info.onInteractionEnd) {
122
- this.editor.setCurrentTool(this.info.onInteractionEnd, this.info)
133
+ const { onInteractionEnd } = this.info
134
+ if (onInteractionEnd) {
135
+ if (typeof onInteractionEnd === 'string') {
136
+ this.editor.setCurrentTool(onInteractionEnd, this.info)
137
+ } else {
138
+ onInteractionEnd()
139
+ }
123
140
  } else {
124
141
  this.editor.setCroppingShape(null)
125
142
  this.editor.setCurrentTool('select.idle')
@@ -143,7 +143,7 @@ export class Idle extends StateNode {
143
143
  }
144
144
 
145
145
  override onKeyUp(info: TLKeyboardEventInfo) {
146
- switch (info.code) {
146
+ switch (info.key) {
147
147
  case 'Enter': {
148
148
  this.editor.setCroppingShape(null)
149
149
  this.editor.setCurrentTool('select.idle', {})