tldraw 4.1.0-canary.cfa7ba5fd57f → 4.1.0-canary.d716f21afebb

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 (45) hide show
  1. package/dist-cjs/index.d.ts +15 -11
  2. package/dist-cjs/index.js +3 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/defaultEmbedDefinitions.js +0 -24
  5. package/dist-cjs/lib/defaultEmbedDefinitions.js.map +2 -2
  6. package/dist-cjs/lib/defaultExternalContentHandlers.js +8 -31
  7. package/dist-cjs/lib/defaultExternalContentHandlers.js.map +2 -2
  8. package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js +31 -101
  9. package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js.map +2 -2
  10. package/dist-cjs/lib/shapes/bookmark/bookmarks.js +138 -0
  11. package/dist-cjs/lib/shapes/bookmark/bookmarks.js.map +7 -0
  12. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js +25 -3
  13. package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js.map +2 -2
  14. package/dist-cjs/lib/ui/context/actions.js +23 -29
  15. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  16. package/dist-cjs/lib/ui/version.js +3 -3
  17. package/dist-cjs/lib/ui/version.js.map +1 -1
  18. package/dist-esm/index.d.mts +15 -11
  19. package/dist-esm/index.mjs +3 -1
  20. package/dist-esm/index.mjs.map +2 -2
  21. package/dist-esm/lib/defaultEmbedDefinitions.mjs +0 -24
  22. package/dist-esm/lib/defaultEmbedDefinitions.mjs.map +2 -2
  23. package/dist-esm/lib/defaultExternalContentHandlers.mjs +8 -31
  24. package/dist-esm/lib/defaultExternalContentHandlers.mjs.map +2 -2
  25. package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs +34 -101
  26. package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs.map +2 -2
  27. package/dist-esm/lib/shapes/bookmark/bookmarks.mjs +124 -0
  28. package/dist-esm/lib/shapes/bookmark/bookmarks.mjs.map +7 -0
  29. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs +26 -3
  30. package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs.map +2 -2
  31. package/dist-esm/lib/ui/context/actions.mjs +23 -29
  32. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  33. package/dist-esm/lib/ui/version.mjs +3 -3
  34. package/dist-esm/lib/ui/version.mjs.map +1 -1
  35. package/package.json +3 -3
  36. package/src/index.ts +1 -0
  37. package/src/lib/defaultEmbedDefinitions.ts +0 -24
  38. package/src/lib/defaultExternalContentHandlers.ts +10 -35
  39. package/src/lib/shapes/bookmark/BookmarkShapeUtil.tsx +39 -133
  40. package/src/lib/shapes/bookmark/bookmarks.ts +170 -0
  41. package/src/lib/shapes/embed/EmbedShapeUtil.tsx +28 -2
  42. package/src/lib/ui/context/actions.tsx +27 -31
  43. package/src/lib/ui/version.ts +3 -3
  44. package/src/lib/utils/embeds/embeds.test.ts +0 -34
  45. package/src/test/bookmark-shapes.test.ts +129 -7
@@ -31,6 +31,7 @@ import {
31
31
  toRichText,
32
32
  } from '@tldraw/editor'
33
33
  import { EmbedDefinition } from './defaultEmbedDefinitions'
34
+ import { createBookmarkFromUrl } from './shapes/bookmark/bookmarks'
34
35
  import { EmbedShapeUtil } from './shapes/embed/EmbedShapeUtil'
35
36
  import { getCroppedImageDataForReplacedImage } from './shapes/shared/crop'
36
37
  import { FONT_FAMILIES, FONT_SIZES, TEXT_PROPS } from './shapes/shared/default-shape-constants'
@@ -572,42 +573,16 @@ export async function defaultHandleExternalUrlContent(
572
573
  ? editor.inputs.currentPagePoint
573
574
  : editor.getViewportPageBounds().center)
574
575
 
575
- const assetId: TLAssetId = AssetRecordType.createId(getHashForString(url))
576
- const shape = createEmptyBookmarkShape(editor, url, position)
577
-
578
- // Use an existing asset if we have one, or else else create a new one
579
- let asset = editor.getAsset(assetId) as TLAsset
580
- let shouldAlsoCreateAsset = false
581
- if (!asset) {
582
- shouldAlsoCreateAsset = true
583
- try {
584
- const bookmarkAsset = await editor.getAssetForExternalContent({ type: 'url', url })
585
- if (!bookmarkAsset) throw Error('Could not create an asset')
586
- asset = bookmarkAsset
587
- } catch {
588
- toasts.addToast({
589
- title: msg('assets.url.failed'),
590
- severity: 'error',
591
- })
592
- return
593
- }
594
- }
595
-
596
- editor.run(() => {
597
- if (shouldAlsoCreateAsset) {
598
- editor.createAssets([asset])
599
- }
576
+ // Use the new function to create the bookmark
577
+ const result = await createBookmarkFromUrl(editor, { url, center: position })
600
578
 
601
- editor.updateShapes([
602
- {
603
- id: shape.id,
604
- type: shape.type,
605
- props: {
606
- assetId: asset.id,
607
- },
608
- },
609
- ])
610
- })
579
+ if (!result.ok) {
580
+ toasts.addToast({
581
+ title: msg('assets.url.failed'),
582
+ severity: 'error',
583
+ })
584
+ return
585
+ }
611
586
  }
612
587
 
613
588
  /** @public */
@@ -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,14 +169,14 @@ 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
177
  <a
172
178
  className="tl-bookmark__link"
173
- href={shape.props.url || ''}
179
+ href={url || ''}
174
180
  target="_blank"
175
181
  rel="noopener noreferrer"
176
182
  draggable={false}
@@ -187,7 +193,7 @@ function BookmarkShapeComponent({ shape }: { shape: TLBookmarkShape }) {
187
193
  ) : null}
188
194
  <a
189
195
  className="tl-bookmark__link"
190
- href={shape.props.url || ''}
196
+ href={url || ''}
191
197
  target="_blank"
192
198
  rel="noopener noreferrer"
193
199
  draggable={false}
@@ -218,103 +224,3 @@ function BookmarkShapeComponent({ shape }: { shape: TLBookmarkShape }) {
218
224
  </HTMLContainer>
219
225
  )
220
226
  }
221
-
222
- function getBookmarkSize(editor: Editor, shape: TLBookmarkShape) {
223
- const asset = (
224
- shape.props.assetId ? editor.getAsset(shape.props.assetId) : null
225
- ) as TLBookmarkAsset
226
-
227
- let h = BOOKMARK_HEIGHT
228
-
229
- if (asset) {
230
- if (!asset.props.image) {
231
- if (!asset.props.title) {
232
- h = BOOKMARK_JUST_URL_HEIGHT
233
- } else {
234
- h = SHORT_BOOKMARK_HEIGHT
235
- }
236
- }
237
- }
238
-
239
- return {
240
- ...shape,
241
- props: {
242
- ...shape.props,
243
- h,
244
- },
245
- }
246
- }
247
-
248
- /** @internal */
249
- export const getHumanReadableAddress = (shape: TLBookmarkShape) => {
250
- try {
251
- const url = new URL(shape.props.url)
252
- // we want the hostname without any www
253
- return url.hostname.replace(/^www\./, '')
254
- } catch {
255
- return shape.props.url
256
- }
257
- }
258
-
259
- function updateBookmarkAssetOnUrlChange(editor: Editor, shape: TLBookmarkShape) {
260
- const { url } = shape.props
261
-
262
- // Derive the asset id from the URL
263
- const assetId: TLAssetId = AssetRecordType.createId(getHashForString(url))
264
-
265
- if (editor.getAsset(assetId)) {
266
- // Existing asset for this URL?
267
- if (shape.props.assetId !== assetId) {
268
- editor.updateShapes<TLBookmarkShape>([
269
- {
270
- id: shape.id,
271
- type: shape.type,
272
- props: { assetId },
273
- },
274
- ])
275
- }
276
- } else {
277
- // No asset for this URL?
278
-
279
- // First, clear out the existing asset reference
280
- editor.updateShapes<TLBookmarkShape>([
281
- {
282
- id: shape.id,
283
- type: shape.type,
284
- props: { assetId: null },
285
- },
286
- ])
287
-
288
- // Then try to asyncronously create a new one
289
- createBookmarkAssetOnUrlChange(editor, shape)
290
- }
291
- }
292
-
293
- const createBookmarkAssetOnUrlChange = debounce(async (editor: Editor, shape: TLBookmarkShape) => {
294
- if (editor.isDisposed) return
295
-
296
- const { url } = shape.props
297
-
298
- // Create the asset using the external content manager's createAssetFromUrl method.
299
- // This may be overwritten by the user (for example, we overwrite it on tldraw.com)
300
- const asset = await editor.getAssetForExternalContent({ type: 'url', url })
301
-
302
- if (!asset) {
303
- // No asset? Just leave the bookmark as a null assetId.
304
- return
305
- }
306
-
307
- editor.run(() => {
308
- // Create the new asset
309
- editor.createAssets([asset])
310
-
311
- // And update the shape
312
- editor.updateShapes<TLBookmarkShape>([
313
- {
314
- id: shape.id,
315
- type: shape.type,
316
- props: { assetId: asset.id },
317
- },
318
- ])
319
- })
320
- }, 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(
@@ -5,6 +5,7 @@ import {
5
5
  Editor,
6
6
  HALF_PI,
7
7
  PageRecordType,
8
+ Result,
8
9
  TLBookmarkShape,
9
10
  TLEmbedShape,
10
11
  TLFrameShape,
@@ -24,6 +25,7 @@ import {
24
25
  useMaybeEditor,
25
26
  } from '@tldraw/editor'
26
27
  import * as React from 'react'
28
+ import { createBookmarkFromUrl } from '../../shapes/bookmark/bookmarks'
27
29
  import { fitFrameToContent, removeFrame } from '../../utils/frames/frames'
28
30
  import { generateShapeAnnouncementMessage } from '../components/A11y'
29
31
  import { EditLinkDialog } from '../components/EditLinkDialog'
@@ -387,45 +389,39 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
387
389
  {
388
390
  id: 'convert-to-bookmark',
389
391
  label: 'action.convert-to-bookmark',
390
- onSelect(source) {
392
+ async onSelect(source) {
391
393
  if (!canApplySelectionAction()) return
392
394
  if (mustGoBackToSelectToolFirst()) return
393
395
 
394
- editor.run(() => {
395
- trackEvent('convert-to-bookmark', { source })
396
- const shapes = editor.getSelectedShapes()
396
+ trackEvent('convert-to-bookmark', { source })
397
+ const shapes = editor.getSelectedShapes()
397
398
 
398
- const createList: TLShapePartial[] = []
399
- const deleteList: TLShapeId[] = []
400
- for (const shape of shapes) {
401
- if (!shape || !editor.isShapeOfType<TLEmbedShape>(shape, 'embed') || !shape.props.url)
402
- continue
399
+ const markId = editor.markHistoryStoppingPoint('convert shapes to bookmark')
403
400
 
404
- const newPos = new Vec(shape.x, shape.y)
405
- newPos.rot(-shape.rotation)
406
- newPos.add(new Vec(shape.props.w / 2 - 300 / 2, shape.props.h / 2 - 320 / 2)) // see bookmark shape util
407
- newPos.rot(shape.rotation)
408
- const partial: TLShapePartial<TLBookmarkShape> = {
409
- id: createShapeId(),
410
- type: 'bookmark',
411
- rotation: shape.rotation,
412
- x: newPos.x,
413
- y: newPos.y,
414
- opacity: 1,
415
- props: {
416
- url: shape.props.url,
417
- },
418
- }
401
+ const creationPromises: Promise<Result<any, any>>[] = []
419
402
 
420
- createList.push(partial)
421
- deleteList.push(shape.id)
422
- }
403
+ for (const shape of shapes) {
404
+ if (!shape || !editor.isShapeOfType<TLEmbedShape>(shape, 'embed') || !shape.props.url)
405
+ continue
423
406
 
424
- editor.markHistoryStoppingPoint('convert shapes to bookmark')
407
+ const center = editor.getShapePageBounds(shape)?.center
425
408
 
426
- // Should be able to create the shape since we're about to delete the other other
427
- editor.deleteShapes(deleteList)
428
- editor.createShapes(createList)
409
+ if (!center) continue
410
+ editor.deleteShapes([shape.id])
411
+
412
+ creationPromises.push(
413
+ createBookmarkFromUrl(editor, { url: shape.props.url, center }).then((res) => {
414
+ if (!res.ok) {
415
+ throw new Error(res.error)
416
+ }
417
+ return res
418
+ })
419
+ )
420
+ }
421
+
422
+ await Promise.all(creationPromises).catch((error) => {
423
+ editor.bailToMark(markId)
424
+ console.error(error)
429
425
  })
430
426
  },
431
427
  },
@@ -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 = '4.1.0-canary.cfa7ba5fd57f'
4
+ export const version = '4.1.0-canary.d716f21afebb'
5
5
  export const publishDates = {
6
6
  major: '2025-09-18T14:39:22.803Z',
7
- minor: '2025-10-13T13:35:58.457Z',
8
- patch: '2025-10-13T13:35:58.457Z',
7
+ minor: '2025-10-14T08:44:03.625Z',
8
+ patch: '2025-10-14T08:44:03.625Z',
9
9
  }
@@ -355,23 +355,6 @@ const MATCH_URL_TEST_URLS: (MatchUrlTestNoMatchDef | MatchUrlTestMatchDef)[] = [
355
355
  url: 'https://vimeo.com/foobar',
356
356
  match: false,
357
357
  },
358
- // excalidraw
359
- {
360
- url: 'https://excalidraw.com/#room=asdkjashdkjhaskdjh,sadkjhakjshdkjahd',
361
- match: true,
362
- output: {
363
- type: 'excalidraw',
364
- embedUrl: `https://excalidraw.com/#room=asdkjashdkjhaskdjh,sadkjhakjshdkjahd`,
365
- },
366
- },
367
- {
368
- url: 'https://excalidraw.com',
369
- match: false,
370
- },
371
- {
372
- url: 'https://excalidraw.com/help',
373
- match: false,
374
- },
375
358
  //desmos
376
359
  {
377
360
  url: 'https://www.desmos.com/calculator/js9hryvejc',
@@ -687,23 +670,6 @@ const MATCH_EMBED_TEST_URLS: (MatchEmbedTestMatchDef | MatchEmbedTestNoMatchDef)
687
670
  embedUrl: 'https://vimeo.com/foobar',
688
671
  match: false,
689
672
  },
690
- // excalidraw
691
- {
692
- embedUrl: 'https://excalidraw.com/#room=asdkjashdkjhaskdjh,sadkjhakjshdkjahd',
693
- match: true,
694
- output: {
695
- type: 'excalidraw',
696
- url: `https://excalidraw.com/#room=asdkjashdkjhaskdjh,sadkjhakjshdkjahd`,
697
- },
698
- },
699
- {
700
- embedUrl: 'https://excalidraw.com',
701
- match: false,
702
- },
703
- {
704
- embedUrl: 'https://excalidraw.com/help',
705
- match: false,
706
- },
707
673
  // desmos
708
674
  {
709
675
  embedUrl: 'https://www.desmos.com/calculator/js9hryvejc?embed',