tldraw 5.6.0 → 5.6.1
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.
- package/DOCS.md +2 -1
- package/RELEASE_NOTES.md +106 -3
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js +5 -4
- package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/bookmark/bookmarks.js +25 -4
- package/dist-cjs/lib/shapes/bookmark/bookmarks.js.map +2 -2
- package/dist-cjs/lib/ui/components/EditLinkDialog.js +15 -17
- package/dist-cjs/lib/ui/components/EditLinkDialog.js.map +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js +46 -19
- package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js.map +3 -3
- package/dist-cjs/lib/ui/version.js +2 -2
- package/dist-cjs/lib/ui/version.js.map +1 -1
- package/dist-cjs/lib/utils/linkUrl.js +39 -0
- package/dist-cjs/lib/utils/linkUrl.js.map +7 -0
- package/dist-cjs/lib/utils/text/richText.js +4 -1
- package/dist-cjs/lib/utils/text/richText.js.map +2 -2
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs +6 -4
- package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/bookmark/bookmarks.mjs +25 -4
- package/dist-esm/lib/shapes/bookmark/bookmarks.mjs.map +2 -2
- package/dist-esm/lib/ui/components/EditLinkDialog.mjs +16 -18
- package/dist-esm/lib/ui/components/EditLinkDialog.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs +36 -19
- package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs.map +2 -2
- package/dist-esm/lib/ui/version.mjs +2 -2
- package/dist-esm/lib/ui/version.mjs.map +1 -1
- package/dist-esm/lib/utils/linkUrl.mjs +19 -0
- package/dist-esm/lib/utils/linkUrl.mjs.map +7 -0
- package/dist-esm/lib/utils/text/richText.mjs +5 -1
- package/dist-esm/lib/utils/text/richText.mjs.map +2 -2
- package/package.json +6 -6
- package/src/lib/shapes/bookmark/BookmarkShapeUtil.tsx +6 -6
- package/src/lib/shapes/bookmark/bookmarks.ts +38 -5
- package/src/lib/ui/components/EditLinkDialog.tsx +22 -26
- package/src/lib/ui/components/Toolbar/LinkEditor.tsx +38 -20
- package/src/lib/ui/version.ts +2 -2
- package/src/lib/ui.css +9 -2
- package/src/lib/utils/linkUrl.test.ts +33 -0
- package/src/lib/utils/linkUrl.ts +30 -0
- package/src/lib/utils/text/richText.ts +4 -0
- package/src/test/bookmark-shapes.test.ts +62 -2
- package/src/test/ui/EditLinkDialog.test.tsx +53 -2
- package/src/test/ui/LinkEditor.test.tsx +71 -0
- package/tldraw.css +9 -2
package/DOCS.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# tldraw Documentation
|
|
2
2
|
|
|
3
|
-
Version: `5.6.
|
|
3
|
+
Version: `5.6.1`
|
|
4
4
|
|
|
5
5
|
This file is generated during package publishing from the tldraw docs content for this exact package version.
|
|
6
6
|
|
|
@@ -383,6 +383,7 @@ We ship an experimental `tldraw-migrate` agent skill that helps a coding agent u
|
|
|
383
383
|
|
|
384
384
|
#### v5.x
|
|
385
385
|
|
|
386
|
+
- [v5.6](https://tldraw.dev/releases/v5.6.0) - ICU MessageFormat and react-intl for translations, action-driven menu gating, a ThrottledFunction type in @tldraw/utils, commenting improvements, and fixes across selection, undo/redo, local persistence, sync, and the store
|
|
386
387
|
- [v5.5](https://tldraw.dev/releases/v5.5.0) - Smart typography and matched-pair wrapping in rich text, pasting links onto shapes, a replaceable note attribution badge, TipTap's extension API re-exported from tldraw, and a reliability pass across the SDK
|
|
387
388
|
- [v5.4](https://tldraw.dev/releases/v5.4.0) - A center align operation, a tleditors registry of mounted editors, faster signals and store layers, and a broad reliability pass across the SDK
|
|
388
389
|
- [v5.3](https://tldraw.dev/releases/v5.3.0) - Commenting with anchored threads on the canvas, new collaboration packages, geo shape flipping, crop snapping, and faster viewport culling
|
package/RELEASE_NOTES.md
CHANGED
|
@@ -1,39 +1,119 @@
|
|
|
1
1
|
# Releases
|
|
2
2
|
|
|
3
|
-
Version: `5.6.
|
|
3
|
+
Version: `5.6.1`
|
|
4
4
|
|
|
5
5
|
This file is generated during package publishing from the tldraw release notes content for this exact package version.
|
|
6
6
|
|
|
7
|
+
## v5.6.1
|
|
8
|
+
|
|
9
|
+
So far this release lets shapes decide whether they can flip, gates action execution on action predicates across menus and shortcuts, adds avatar and byline slots to `@tldraw/commenting`, improves crop mode, switches sync server templates to `node:sqlite`, and runs agent starter kit actions through tool calls. It also includes bug fixes across `.tldr` asset preservation, media asset handling, frame hit testing, text shape bounds, cursor chat, locked frame shortcuts, screen readers, and the comment composer.
|
|
10
|
+
|
|
11
|
+
### API changes
|
|
12
|
+
|
|
13
|
+
- 💥 Add `ShapeUtil.canFlip(shape)`, which decides whether the flip menu items and shift+H / shift+V act on a single selected shape. It defaults to `false`, so a lone custom shape no longer gets the flip menu items or shortcuts. If your shape changes when flipped (for example it handles negative scale in `onResize`), add `override canFlip() { return true }` to its util. Multi-shape flips are unchanged. ([#11041](https://github.com/tldraw/tldraw/pull/11041))
|
|
14
|
+
- 💥 Move the Cmd+G and Cmd+Alt+G shortcuts from the `group` and `frame-selection` actions to new `toggle-group` and `toggle-frame` actions, which pick `group` or `ungroup`, and `frame-selection` or `remove-frame`, from the selection. `group` and `frame-selection` no longer have a `kbd`, so menus no longer show a shortcut next to them. To rebind or disable these shortcuts, override `actions['toggle-group']` or `actions['toggle-frame']` instead, for example `actions['toggle-group'].kbd = 'cmd+k,ctrl+k'` or `delete actions['toggle-group']`; setting `kbd` on `group` or `frame-selection` now registers a separate shortcut that only groups or frames. ([#11043](https://github.com/tldraw/tldraw/pull/11043))
|
|
15
|
+
- 💥 Remove unused `help-menu.discord`, `help-menu.github`, and `help-menu.twitter` keys from `TLUiTranslationKey`. ([#11258](https://github.com/tldraw/tldraw/pull/11258))
|
|
16
|
+
- Actions don't run when `isAvailable` or `isEnabled` returns false, or when the editor is readonly and the action isn't `readonlyOk`, whether they're triggered from a menu, a keyboard shortcut or an `onSelect` call on an action from `useActions()`. The copy, cut and paste shortcuts still come from native clipboard events and aren't gated. If your app calls a custom action directly in readonly mode, set `readonlyOk: true` on it. An override that replaces a built-in's `onSelect`, in place or by spreading it, keeps the built-in's `isEnabled`, so the action no longer runs from a shortcut or `useActions()` when that returns false; override `isEnabled` too if your `onSelect` handles that case. ([#11043](https://github.com/tldraw/tldraw/pull/11043))
|
|
17
|
+
- Add `Editor.getShapesInReadingOrder(shapes)` to sort an arbitrary set of shapes into reading order. ([#10505](https://github.com/tldraw/tldraw/pull/10505))
|
|
18
|
+
- Add `CommentByline` and `Avatar` component slots to `@tldraw/commenting`, so you can change how comment authors and their avatars are shown. ([#11447](https://github.com/tldraw/tldraw/pull/11447))
|
|
19
|
+
|
|
20
|
+
### Improvements
|
|
21
|
+
|
|
22
|
+
- Keyboard shortcuts no longer do things the menus don't allow: Shift+H and Shift+V no longer flip a lone text, Shift+F no longer flattens a lone image, Cmd+A and Cmd+P do nothing on an empty page, and Cmd+G no longer groups an arrow away from a shape it's bound to. ([#11043](https://github.com/tldraw/tldraw/pull/11043))
|
|
23
|
+
- Add Cmd+Alt+Shift+G as an explicit Remove frame shortcut. Cmd+G and Cmd+Alt+G continue to toggle grouping and framing when the selection allows the corresponding action. ([#11043](https://github.com/tldraw/tldraw/pull/11043))
|
|
24
|
+
- Cursor chat opens with `/` in any tool, and its menu item shows in any tool. ([#11043](https://github.com/tldraw/tldraw/pull/11043))
|
|
25
|
+
- Exit crop mode when clicking any shape other than the one being cropped, instead of moving the crop to the clicked image. ([#10832](https://github.com/tldraw/tldraw/pull/10832))
|
|
26
|
+
- Run agent starter kit actions through tool calls rather than plain JSON text output, with streaming partial updates and follow-up turns, and let actions provide their own results via `AgentActionUtil.getResult`. ([#11147](https://github.com/tldraw/tldraw/pull/11147))
|
|
27
|
+
- Add OpenRouter support to the agent and branching-chat starter kits via `OPENROUTER_API_KEY`. ([#11103](https://github.com/tldraw/tldraw/pull/11103))
|
|
28
|
+
- Use Node's built-in `node:sqlite` instead of `better-sqlite3` in the Node and socket.io sync server starter templates, removing the need for a native module dependency. ([#11175](https://github.com/tldraw/tldraw/pull/11175))
|
|
29
|
+
|
|
30
|
+
### Bug fixes
|
|
31
|
+
|
|
32
|
+
- Fix `.tldr` files dropping assets that custom records refer to; assets named by any record in the file are now preserved. ([#11406](https://github.com/tldraw/tldraw/pull/11406))
|
|
33
|
+
- Fix pressing Escape while dragging a note's clone handle leaving the new note behind and switching to the note tool. ([#10460](https://github.com/tldraw/tldraw/pull/10460))
|
|
34
|
+
- Fix the Delete, Duplicate, and Group shortcuts acting on children of locked frames and groups, matching the menu behavior. ([#10479](https://github.com/tldraw/tldraw/pull/10479))
|
|
35
|
+
- Fix screen-reader announcements for groups and for nested shapes inside frames or groups. ([#10505](https://github.com/tldraw/tldraw/pull/10505))
|
|
36
|
+
- Fix the follow button tooltip saying "Following" before following anyone. ([#10511](https://github.com/tldraw/tldraw/pull/10511))
|
|
37
|
+
- Fix Windows and Linux shortcut labels showing `⇧` instead of `Shift`. ([#10511](https://github.com/tldraw/tldraw/pull/10511))
|
|
38
|
+
- Fix the Delete key not working when the keyboard shortcuts preference is disabled, matching Enter, Tab, and the arrows. ([#10511](https://github.com/tldraw/tldraw/pull/10511))
|
|
39
|
+
- Fix a crash when dropping an audio-only video file (for example `.webm`) or a file with no size on the canvas. ([#11220](https://github.com/tldraw/tldraw/pull/11220))
|
|
40
|
+
- Fix replacing an image or video when the upload fails: the shape now keeps its previous media and an error toast shows. ([#11220](https://github.com/tldraw/tldraw/pull/11220))
|
|
41
|
+
- Fix clicks in the empty space above a frame selecting the frame when zoomed out. ([#11253](https://github.com/tldraw/tldraw/pull/11253))
|
|
42
|
+
- Fix cursor chat closing immediately when opened from the context menu. ([#11054](https://github.com/tldraw/tldraw/pull/11054))
|
|
43
|
+
- Fix the comment composer's text jumping up when a comment wraps onto a second line. ([#11255](https://github.com/tldraw/tldraw/pull/11255))
|
|
44
|
+
- Fix the selection box of a text shape shrinking when an empty heading is created. ([#11219](https://github.com/tldraw/tldraw/pull/11219))
|
|
45
|
+
- Remove an unused `data-iseditinganything` attribute from `.tlui-layout`, along with the editing-state reactor that set it on iOS and Android. ([#10502](https://github.com/tldraw/tldraw/pull/10502))
|
|
46
|
+
|
|
7
47
|
## v5.6.0
|
|
8
48
|
|
|
9
|
-
|
|
49
|
+
[View on GitHub](https://github.com/tldraw/tldraw/releases/tag/v5.6.0)
|
|
50
|
+
|
|
51
|
+
This release introduces ICU MessageFormat and react-intl for translations, action-driven menu gating, and a `ThrottledFunction` type in `@tldraw/utils`. It also improves commenting, canvas navigation, and the select tool, and includes a broad set of bug fixes across selection, undo/redo, local persistence, sync, and the store.
|
|
52
|
+
|
|
53
|
+
### What's new
|
|
54
|
+
|
|
55
|
+
#### ICU MessageFormat and react-intl for translations ([#8036](https://github.com/tldraw/tldraw/pull/8036))
|
|
56
|
+
|
|
57
|
+
The SDK's UI strings now use [ICU MessageFormat](https://unicode-org.github.io/icu/userguide/format_parse/messages/), allowing messages to support pluralization, selections, and values interpolation cleanly across languages. We've also added react-intl authoring on top: `defineMessages` and `<F>` declare and render messages with their default English next to the code that uses them.
|
|
58
|
+
|
|
59
|
+
Existing translations overridden by ID through `overrides.translations` continue to work unchanged.
|
|
10
60
|
|
|
11
61
|
### API changes
|
|
12
62
|
|
|
13
|
-
- Add
|
|
63
|
+
- Add ICU MessageFormat translation support with `defineMessages`, `<F>`, and `useTldrawI18n`. `useTranslation`'s `msg` now supports interpolating values through an optional second argument and accepts declared message descriptors. ([#8036](https://github.com/tldraw/tldraw/pull/8036))
|
|
14
64
|
- Add `isAvailable(editor)`, `isEnabled(editor)` and `isChecked(editor)` to actions. Menu items built with `TldrawUiMenuActionItem` and `TldrawUiMenuActionCheckboxItem` read them: an unavailable action is hidden, a disabled one is greyed out or hidden depending on `whenDisabled: 'hide' | 'disable'`. `useSomeActionsEnabled` returns whether any of the given actions is available and enabled, so a submenu can hide when none of its items can run. If you replace a built-in action with a new object instead of spreading it, it loses its gating, and a toggle's checkbox always shows as unchecked. ([#11038](https://github.com/tldraw/tldraw/pull/11038))
|
|
15
65
|
- `TldrawUiMenuActionItem` now disables itself when its action's `isEnabled` returns false, so custom menus that render built-in actions grey them out when they can't run. The public menu item wrappers, such as `GroupMenuItem`, `FrameSelectionMenuItem` and `ArrangeMenuSubmenu`, now also hide outside the select tool, where their actions do nothing. ([#11038](https://github.com/tldraw/tldraw/pull/11038))
|
|
66
|
+
- Add a `ThrottledFunction<T>` type to `@tldraw/utils` for annotating the result of `throttle`. `throttle` now returns this type, with the same runtime behavior. ([#10927](https://github.com/tldraw/tldraw/pull/10927))
|
|
67
|
+
- Add `startCommentAt(editor, point)` to `@tldraw/commenting` for starting a comment thread at a specific canvas location from outside the comment tool. ([#10970](https://github.com/tldraw/tldraw/pull/10970))
|
|
68
|
+
- `TLSocketRoom.handleSocketMessage(sessionId, message, socket?)`, `handleSocketClose(sessionId, socket?)`, and `handleSocketError(sessionId, socket?)` now accept an optional originating socket parameter so messages and events from superseded connections are ignored. ([#11067](https://github.com/tldraw/tldraw/pull/11067))
|
|
69
|
+
- Add `LaserTool.startScribble()` which adds a laser scribble to the current session, starting a fresh session if none is active. ([#10781](https://github.com/tldraw/tldraw/pull/10781))
|
|
16
70
|
|
|
17
71
|
### Improvements
|
|
18
72
|
|
|
19
73
|
- Menus no longer offer actions that would do nothing: grouping locked shapes, flipping a locked shape, unlocking when nothing is locked, exporting all shapes on an empty page, moving to a new page at the page limit, and grouping an arrow away from a shape it's bound to. The main menu hides Paste, instead of disabling it, in browsers that can't read the clipboard. ([#11038](https://github.com/tldraw/tldraw/pull/11038))
|
|
74
|
+
- Allow keyboard navigation (Tab, Ctrl/Cmd+arrow, and the "Move focus to canvas" button) to reach locked shapes again, so keyboard users can select and unlock them. ([#11134](https://github.com/tldraw/tldraw/pull/11134))
|
|
75
|
+
- Add a **Comment** item to the default canvas context menu when commenting is configured. It opens the comment composer where you right-clicked. ([#11095](https://github.com/tldraw/tldraw/pull/11095))
|
|
76
|
+
- Move the comments filter menu to the right of the hide comments toggle in the comments panel header. ([#11135](https://github.com/tldraw/tldraw/pull/11135))
|
|
77
|
+
- Cancel comment draft placement and return to the select tool when clicking the canvas, instead of moving the draft comment. ([#10969](https://github.com/tldraw/tldraw/pull/10969))
|
|
20
78
|
- Draw the hinted outline around shapes, such as a frame you're dragging a shape into, at 2px instead of 2.5px. ([#10952](https://github.com/tldraw/tldraw/pull/10952))
|
|
21
79
|
- Speed up `store.query.index()` and `store.query.ids()` updates by no longer allocating for each change. ([#10228](https://github.com/tldraw/tldraw/pull/10228))
|
|
22
80
|
|
|
23
81
|
### Bug fixes
|
|
24
82
|
|
|
25
83
|
- Fix the edge scrolling preference showing as off when edge scrolling is on at a speed other than 1, such as 0.5 or 2. ([#11038](https://github.com/tldraw/tldraw/pull/11038))
|
|
84
|
+
- Fix edge scrolling jumping to partial speed after its start delay. ([#11126](https://github.com/tldraw/tldraw/pull/11126))
|
|
26
85
|
- Fix three resize issues: flipping a rotated selection gave its children the wrong rotation, shapes not aligned with the selection received `onResizeStart` and `onResizeEnd` more than once, and `resizeBox` slid the fixed edge when a shape hit its `maxWidth` or `maxHeight`. ([#10351](https://github.com/tldraw/tldraw/pull/10351))
|
|
27
86
|
- Fix duplicating a page moving its shapes when they were off screen, and starting the new page with the current page's camera instead of the duplicated page's. ([#10465](https://github.com/tldraw/tldraw/pull/10465))
|
|
87
|
+
- Fix the page menu closing and getting stuck mid-drag when Escape is pressed while reordering pages. ([#11115](https://github.com/tldraw/tldraw/pull/11115))
|
|
88
|
+
- Fix an empty line under a heading in a text shape that could not be deleted. ([#11114](https://github.com/tldraw/tldraw/pull/11114))
|
|
89
|
+
- Fix the "rhombus-2" (rhombus left) geo tool showing a raw translation key as its label. ([#11062](https://github.com/tldraw/tldraw/pull/11062))
|
|
90
|
+
- Fix the keyboard shortcuts dialog opening via keyboard shortcut when `KeyboardShortcutsDialog` is overridden with `null`. ([#11019](https://github.com/tldraw/tldraw/pull/11019))
|
|
91
|
+
- Fix the rich text toolbar reporting the wrong operation in `onUiEvent` for italic, code, and highlight. ([#11018](https://github.com/tldraw/tldraw/pull/11018))
|
|
92
|
+
- Fix undo after double-clicking a frame's corner or edge to fit it to content creating an inconsistent history step. ([#11075](https://github.com/tldraw/tldraw/pull/11075))
|
|
93
|
+
- Fix undo reverting an earlier edit after brushing to select, right-clicking an empty canvas to deselect, pressing Enter on a group, or navigating the selection with the keyboard. ([#10476](https://github.com/tldraw/tldraw/pull/10476))
|
|
94
|
+
- Fix clicking a child of a locked group selecting the locked group. ([#10180](https://github.com/tldraw/tldraw/pull/10180))
|
|
95
|
+
- Fix bookmarks, notes, and other non-resizing shapes being mispositioned when their containing group is resized or flipped. ([#10619](https://github.com/tldraw/tldraw/pull/10619))
|
|
96
|
+
- Fix bounds snapping not engaging while resizing or cropping shapes inside slightly rotated frames or groups. ([#10181](https://github.com/tldraw/tldraw/pull/10181))
|
|
28
97
|
- Fix the arrow tool's precise mode carrying over when you move to a different target shape. ([#10244](https://github.com/tldraw/tldraw/pull/10244))
|
|
29
98
|
- Fix holding Cmd/Ctrl+Shift+Arrow switching from selecting a parent or child to selecting the adjacent shape once the key starts repeating. ([#10184](https://github.com/tldraw/tldraw/pull/10184))
|
|
99
|
+
- Fix arrow-key nudging moving diagonally after using a Cmd+Arrow shortcut on macOS. ([#10892](https://github.com/tldraw/tldraw/pull/10892))
|
|
100
|
+
- Fix the eraser sometimes dropping a highlighted shape when dragging near a group. ([#10182](https://github.com/tldraw/tldraw/pull/10182))
|
|
30
101
|
- Fix `editor.setCursor` throwing for the rotate and resize cursor types, and hex cursor colors breaking SVG cursors. ([#10350](https://github.com/tldraw/tldraw/pull/10350))
|
|
102
|
+
- Fix `editor.animateShapes` throwing a `TypeError` when interpolating draw or highlight shapes to or from empty segments. ([#10771](https://github.com/tldraw/tldraw/pull/10771))
|
|
103
|
+
- Fix the laser tool crashing when its scribble session times out mid-stroke. ([#10781](https://github.com/tldraw/tldraw/pull/10781))
|
|
104
|
+
- Fix scribbles added without points disappearing after one idle frame before points could be added on pointer move. ([#10336](https://github.com/tldraw/tldraw/pull/10336))
|
|
105
|
+
- Fix hit testing and viewport culling using stale bounds when text fonts finish loading after measurement, and fix container descendants retaining stale current-page membership when reparented to another page. ([#10341](https://github.com/tldraw/tldraw/pull/10341))
|
|
31
106
|
- Fix edits being lost when an editor remounts with the same `persistenceKey` while the previous one is still saving. ([#10752](https://github.com/tldraw/tldraw/pull/10752))
|
|
107
|
+
- Fix the comment composer requiring a second tap before focusing and raising the software keyboard on iOS. ([#9957](https://github.com/tldraw/tldraw/pull/9957))
|
|
32
108
|
- Fix store changes made in the last frame before a listener is removed never reaching that listener. ([#10802](https://github.com/tldraw/tldraw/pull/10802))
|
|
33
109
|
- Fix a reaction that writes to the store re-running on every unrelated store change. ([#10236](https://github.com/tldraw/tldraw/pull/10236))
|
|
34
110
|
- Fix undo restoring an in-between state after a single `put` updated the same record twice. ([#10203](https://github.com/tldraw/tldraw/pull/10203))
|
|
111
|
+
- Fix store listeners and `extractingChanges` receiving changes from transactions that rolled back. ([#10205](https://github.com/tldraw/tldraw/pull/10205))
|
|
112
|
+
- Fix computed caches in `store.query` not re-running their derive functions when a previously removed record is recreated with the same ID. ([#10225](https://github.com/tldraw/tldraw/pull/10225))
|
|
35
113
|
- Fix `migrateStoreSnapshot` throwing on a malformed persisted schema instead of returning a migration error. ([#10220](https://github.com/tldraw/tldraw/pull/10220))
|
|
36
114
|
- Fix migrations rerunning on records when a persisted schema's sequence version isn't a number. ([#10917](https://github.com/tldraw/tldraw/pull/10917))
|
|
115
|
+
- Fix a record deleted while offline occasionally reappearing after reconnecting. ([#10997](https://github.com/tldraw/tldraw/pull/10997))
|
|
116
|
+
- Fix large chunked sync messages being dropped and active sessions being cancelled by a previous socket's late close or error when reconnecting with the same session ID. ([#11067](https://github.com/tldraw/tldraw/pull/11067))
|
|
37
117
|
- Fix a resumed sync session on a hibernating host skipping the version checks made on first connect, so after a server redeploy a client could be sent changes its schema couldn't handle. It's now rejected with `SERVER_TOO_OLD` or `CLIENT_TOO_OLD`, as on connect. ([#10122](https://github.com/tldraw/tldraw/pull/10122))
|
|
38
118
|
- Fix a record field set to `undefined` getting the sync session kicked with `INVALID_RECORD`, and ignore `__proto__` keys in incoming changes. ([#10118](https://github.com/tldraw/tldraw/pull/10118))
|
|
39
119
|
- Fix older sync clients (protocol version 7) silently falling out of sync when the server sent them text-append changes they don't support. ([#10095](https://github.com/tldraw/tldraw/pull/10095))
|
|
@@ -219,6 +299,29 @@ import { Mark, mergeAttributes } from 'tldraw'
|
|
|
219
299
|
|
|
220
300
|
- Fix `create-tldraw --no-telemetry` being ignored. ([#10789](https://github.com/tldraw/tldraw/pull/10789))
|
|
221
301
|
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
### Patch releases
|
|
305
|
+
|
|
306
|
+
#### v5.5.1
|
|
307
|
+
|
|
308
|
+
- Fix shape hover and selection feeling offset below shapes, caused by the default cursor's hotspot sitting above its visible tip. ([#11033](https://github.com/tldraw/tldraw/pull/11033))
|
|
309
|
+
|
|
310
|
+
[View release on GitHub](https://github.com/tldraw/tldraw/releases/tag/v5.5.1)
|
|
311
|
+
|
|
312
|
+
#### v5.5.2
|
|
313
|
+
|
|
314
|
+
- Fix license domain validation for pages loaded from `blob:` URLs. ([#11040](https://github.com/tldraw/tldraw/pull/11040))
|
|
315
|
+
|
|
316
|
+
[View release on GitHub](https://github.com/tldraw/tldraw/releases/tag/v5.5.2)
|
|
317
|
+
|
|
318
|
+
#### v5.5.4
|
|
319
|
+
|
|
320
|
+
- Increase the default hit test margin from 3 to 4.5, making shape edges easier to hover and select. ([#11108](https://github.com/tldraw/tldraw/pull/11108))
|
|
321
|
+
- Add a tracked license flag that always sends the tracking ping. ([#11178](https://github.com/tldraw/tldraw/pull/11178))
|
|
322
|
+
|
|
323
|
+
[View release on GitHub](https://github.com/tldraw/tldraw/releases/tag/v5.5.4)
|
|
324
|
+
|
|
222
325
|
## v5.4.0
|
|
223
326
|
|
|
224
327
|
[View on GitHub](https://github.com/tldraw/tldraw/releases/tag/v5.4.0)
|
package/dist-cjs/index.js
CHANGED
|
@@ -671,7 +671,7 @@ var import_buildFromV1Document = require("./lib/utils/tldr/buildFromV1Document")
|
|
|
671
671
|
var import_file = require("./lib/utils/tldr/file");
|
|
672
672
|
(0, import_editor.registerTldrawLibraryVersion)(
|
|
673
673
|
"tldraw",
|
|
674
|
-
"5.6.
|
|
674
|
+
"5.6.1",
|
|
675
675
|
"cjs"
|
|
676
676
|
);
|
|
677
677
|
//# sourceMappingURL=index.js.map
|
|
@@ -110,7 +110,7 @@ class BookmarkShapeUtil extends import_editor.BaseBoxShapeUtil {
|
|
|
110
110
|
}
|
|
111
111
|
next = (0, import_bookmarks.resolveBookmarkAssetForUrlChange)(this.editor, shape);
|
|
112
112
|
}
|
|
113
|
-
if (prev.props.assetId !== next.props.assetId) {
|
|
113
|
+
if (prev.props.assetId !== next.props.assetId || prev.props.url !== next.props.url) {
|
|
114
114
|
return (0, import_bookmarks.setBookmarkHeight)(this.editor, next);
|
|
115
115
|
}
|
|
116
116
|
return next === shape ? void 0 : next;
|
|
@@ -135,6 +135,7 @@ function BookmarkShapeComponent({
|
|
|
135
135
|
const asset = resolvedAssetId ? editor.getAsset(resolvedAssetId) : null;
|
|
136
136
|
const isSafariExport = !!(0, import_editor.useSvgExportContext)() && import_editor.tlenv.isSafari;
|
|
137
137
|
const address = (0, import_bookmarks.getHumanReadableAddress)(url);
|
|
138
|
+
const title = asset ? asset.props.title : (0, import_bookmarks.isUrlOnlyBookmarkUrl)(url) ? url : "";
|
|
138
139
|
const [isFaviconValid, setIsFaviconValid] = (0, import_react.useState)(true);
|
|
139
140
|
const onFaviconError = () => setIsFaviconValid(false);
|
|
140
141
|
const markAsHandledOnShiftKey = (0, import_react.useCallback)(
|
|
@@ -155,7 +156,7 @@ function BookmarkShapeComponent({
|
|
|
155
156
|
maxHeight: h
|
|
156
157
|
},
|
|
157
158
|
children: [
|
|
158
|
-
showImageContainer && (
|
|
159
|
+
showImageContainer && (asset ? asset.props.image : !(0, import_bookmarks.isUrlOnlyBookmarkUrl)(url)) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "tl-bookmark__image_container", children: [
|
|
159
160
|
asset ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
160
161
|
"img",
|
|
161
162
|
{
|
|
@@ -169,7 +170,7 @@ function BookmarkShapeComponent({
|
|
|
169
170
|
asset?.props.image && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_HyperlinkButton.HyperlinkButton, { url })
|
|
170
171
|
] }),
|
|
171
172
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "tl-bookmark__copy_container", children: [
|
|
172
|
-
|
|
173
|
+
title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
173
174
|
"a",
|
|
174
175
|
{
|
|
175
176
|
className: "tl-bookmark__link",
|
|
@@ -179,7 +180,7 @@ function BookmarkShapeComponent({
|
|
|
179
180
|
draggable: false,
|
|
180
181
|
onPointerDown: markAsHandledOnShiftKey,
|
|
181
182
|
onPointerUp: markAsHandledOnShiftKey,
|
|
182
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "tl-bookmark__heading", children: (0, import_text.convertCommonTitleHTMLEntities)(
|
|
183
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "tl-bookmark__heading", children: (0, import_text.convertCommonTitleHTMLEntities)(title) })
|
|
183
184
|
}
|
|
184
185
|
) : null,
|
|
185
186
|
asset?.props.description && asset?.props.image ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "tl-bookmark__description", children: asset.props.description }) : null,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/shapes/bookmark/BookmarkShapeUtil.tsx"],
|
|
4
|
-
"sourcesContent": ["// oxlint-disable typescript/no-empty-object-type\nimport {\n\tBaseBoxShapeUtil,\n\tbookmarkShapeMigrations,\n\tbookmarkShapeProps,\n\tdefineMessages,\n\tHTMLContainer,\n\tlerp,\n\tRectangle2d,\n\tT,\n\tTLAssetId,\n\tTLBookmarkAsset,\n\tTLBookmarkShape,\n\tTLBookmarkShapeProps,\n\ttlenv,\n\ttranslateMessage,\n\tuseEditor,\n\tuseSvgExportContext,\n} from '@tldraw/editor'\nimport classNames from 'classnames'\nimport { PointerEventHandler, useCallback, useState } from 'react'\nimport { convertCommonTitleHTMLEntities } from '../../utils/text/text'\nimport type { ShapeOptionsWithDisplayValues } from '../shared/getDisplayValues'\nimport { HyperlinkButton } from '../shared/HyperlinkButton'\nimport { LINK_ICON } from '../shared/icons-editor'\nimport { getRotatedBoxShadow } from '../shared/rotated-box-shadow'\nimport {\n\tBOOKMARK_HEIGHT,\n\tBOOKMARK_WIDTH,\n\tgetBookmarkShapeHeight,\n\tgetHumanReadableAddress,\n\tgetResolvedBookmarkAssetId,\n\tsetBookmarkHeight,\n\tresolveBookmarkAssetForUrlChange,\n} from './bookmarks'\n\n/** @public */\nexport type BookmarkShapeUtilDisplayValues = object\n\n/** @public */\nexport interface BookmarkShapeOptions extends ShapeOptionsWithDisplayValues<\n\tTLBookmarkShape,\n\tBookmarkShapeUtilDisplayValues\n> {}\n\nconst messages = defineMessages({\n\tname: { id: 'tool.bookmark', defaultMessage: 'Bookmark' },\n})\n\n/** @public */\nexport class BookmarkShapeUtil extends BaseBoxShapeUtil<TLBookmarkShape> {\n\tstatic override type = 'bookmark' as const\n\tstatic override props = bookmarkShapeProps\n\tstatic override migrations = bookmarkShapeMigrations\n\n\toverride options: BookmarkShapeOptions = {\n\t\tgetDefaultDisplayValues(): BookmarkShapeUtilDisplayValues {\n\t\t\treturn {}\n\t\t},\n\t\tgetCustomDisplayValues(): Partial<BookmarkShapeUtilDisplayValues> {\n\t\t\treturn {}\n\t\t},\n\t}\n\n\toverride getShapeName() {\n\t\treturn translateMessage(this.editor.i18n(), messages.name)\n\t}\n\n\toverride canResize(shape: TLBookmarkShape) {\n\t\treturn false\n\t}\n\n\toverride hideSelectionBoundsFg(shape: TLBookmarkShape) {\n\t\treturn true\n\t}\n\n\toverride getText(shape: TLBookmarkShape) {\n\t\treturn shape.props.url\n\t}\n\n\toverride getAriaDescriptor(shape: TLBookmarkShape) {\n\t\tconst asset = (\n\t\t\tshape.props.assetId ? this.editor.getAsset(shape.props.assetId) : null\n\t\t) as TLBookmarkAsset | null\n\n\t\tif (!asset?.props.title) return undefined\n\n\t\treturn (\n\t\t\tconvertCommonTitleHTMLEntities(asset.props.title) +\n\t\t\t(asset.props.description ? ', ' + asset.props.description : '')\n\t\t)\n\t}\n\n\toverride getDefaultProps(): TLBookmarkShape['props'] {\n\t\treturn {\n\t\t\turl: '',\n\t\t\tw: BOOKMARK_WIDTH,\n\t\t\th: BOOKMARK_HEIGHT,\n\t\t\tassetId: null,\n\t\t}\n\t}\n\n\toverride getGeometry(shape: TLBookmarkShape) {\n\t\treturn new Rectangle2d({\n\t\t\twidth: shape.props.w,\n\t\t\theight: getBookmarkShapeHeight(this.editor, shape),\n\t\t\tisFilled: true,\n\t\t})\n\t}\n\n\toverride component(shape: TLBookmarkShape) {\n\t\tconst { assetId, url } = shape.props\n\t\tconst h = getBookmarkShapeHeight(this.editor, shape)\n\t\tconst rotation = this.editor.getShapePageTransform(shape)!.rotation()\n\n\t\treturn <BookmarkShapeComponent assetId={assetId} url={url} h={h} rotation={rotation} />\n\t}\n\n\toverride getIndicatorPath(shape: TLBookmarkShape): Path2D {\n\t\tconst path = new Path2D()\n\t\tpath.rect(0, 0, shape.props.w, getBookmarkShapeHeight(this.editor, shape))\n\t\treturn path\n\t}\n\n\toverride onBeforeCreate(next: TLBookmarkShape) {\n\t\treturn setBookmarkHeight(this.editor, next)\n\t}\n\n\toverride onBeforeUpdate(prev: TLBookmarkShape, shape: TLBookmarkShape) {\n\t\tlet next = shape\n\t\tif (prev.props.url !== shape.props.url) {\n\t\t\tif (!T.linkUrl.isValid(shape.props.url)) {\n\t\t\t\treturn { ...shape, props: { ...shape.props, url: prev.props.url } }\n\t\t\t}\n\t\t\tnext = resolveBookmarkAssetForUrlChange(this.editor, shape)\n\t\t}\n\n\t\tif (prev.props.assetId !== next.props.assetId) {\n\t\t\treturn setBookmarkHeight(this.editor, next)\n\t\t}\n\n\t\treturn next === shape ? undefined : next\n\t}\n\toverride getInterpolatedProps(\n\t\tstartShape: TLBookmarkShape,\n\t\tendShape: TLBookmarkShape,\n\t\tt: number\n\t): TLBookmarkShapeProps {\n\t\treturn {\n\t\t\t...(t > 0.5 ? endShape.props : startShape.props),\n\t\t\tw: lerp(startShape.props.w, endShape.props.w, t),\n\t\t\th: lerp(startShape.props.h, endShape.props.h, t),\n\t\t}\n\t}\n}\n\nexport function BookmarkShapeComponent({\n\tassetId,\n\trotation,\n\turl,\n\th,\n\tshowImageContainer = true,\n}: {\n\tassetId: TLAssetId | null\n\trotation: number\n\th: number\n\turl: string\n\tshowImageContainer?: boolean\n}) {\n\tconst editor = useEditor()\n\n\tconst resolvedAssetId = getResolvedBookmarkAssetId(editor, assetId, url)\n\tconst asset = resolvedAssetId ? (editor.getAsset(resolvedAssetId) as TLBookmarkAsset) : null\n\n\tconst isSafariExport = !!useSvgExportContext() && tlenv.isSafari\n\n\tconst address = getHumanReadableAddress(url)\n\n\tconst [isFaviconValid, setIsFaviconValid] = useState(true)\n\tconst onFaviconError = () => setIsFaviconValid(false)\n\n\tconst markAsHandledOnShiftKey = useCallback<PointerEventHandler>(\n\t\t(e) => {\n\t\t\tif (!editor.inputs.getShiftKey()) editor.markEventAsHandled(e)\n\t\t},\n\t\t[editor]\n\t)\n\n\treturn (\n\t\t<HTMLContainer>\n\t\t\t<div\n\t\t\t\tclassName={classNames(\n\t\t\t\t\t'tl-bookmark__container',\n\t\t\t\t\tisSafariExport && 'tl-bookmark__container--safariExport'\n\t\t\t\t)}\n\t\t\t\tstyle={{\n\t\t\t\t\tboxShadow: isSafariExport ? undefined : getRotatedBoxShadow(rotation),\n\t\t\t\t\tmaxHeight: h,\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{showImageContainer && (
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["// oxlint-disable typescript/no-empty-object-type\nimport {\n\tBaseBoxShapeUtil,\n\tbookmarkShapeMigrations,\n\tbookmarkShapeProps,\n\tdefineMessages,\n\tHTMLContainer,\n\tlerp,\n\tRectangle2d,\n\tT,\n\tTLAssetId,\n\tTLBookmarkAsset,\n\tTLBookmarkShape,\n\tTLBookmarkShapeProps,\n\ttlenv,\n\ttranslateMessage,\n\tuseEditor,\n\tuseSvgExportContext,\n} from '@tldraw/editor'\nimport classNames from 'classnames'\nimport { PointerEventHandler, useCallback, useState } from 'react'\nimport { convertCommonTitleHTMLEntities } from '../../utils/text/text'\nimport type { ShapeOptionsWithDisplayValues } from '../shared/getDisplayValues'\nimport { HyperlinkButton } from '../shared/HyperlinkButton'\nimport { LINK_ICON } from '../shared/icons-editor'\nimport { getRotatedBoxShadow } from '../shared/rotated-box-shadow'\nimport {\n\tBOOKMARK_HEIGHT,\n\tBOOKMARK_WIDTH,\n\tgetBookmarkShapeHeight,\n\tgetHumanReadableAddress,\n\tgetResolvedBookmarkAssetId,\n\tisUrlOnlyBookmarkUrl,\n\tsetBookmarkHeight,\n\tresolveBookmarkAssetForUrlChange,\n} from './bookmarks'\n\n/** @public */\nexport type BookmarkShapeUtilDisplayValues = object\n\n/** @public */\nexport interface BookmarkShapeOptions extends ShapeOptionsWithDisplayValues<\n\tTLBookmarkShape,\n\tBookmarkShapeUtilDisplayValues\n> {}\n\nconst messages = defineMessages({\n\tname: { id: 'tool.bookmark', defaultMessage: 'Bookmark' },\n})\n\n/** @public */\nexport class BookmarkShapeUtil extends BaseBoxShapeUtil<TLBookmarkShape> {\n\tstatic override type = 'bookmark' as const\n\tstatic override props = bookmarkShapeProps\n\tstatic override migrations = bookmarkShapeMigrations\n\n\toverride options: BookmarkShapeOptions = {\n\t\tgetDefaultDisplayValues(): BookmarkShapeUtilDisplayValues {\n\t\t\treturn {}\n\t\t},\n\t\tgetCustomDisplayValues(): Partial<BookmarkShapeUtilDisplayValues> {\n\t\t\treturn {}\n\t\t},\n\t}\n\n\toverride getShapeName() {\n\t\treturn translateMessage(this.editor.i18n(), messages.name)\n\t}\n\n\toverride canResize(shape: TLBookmarkShape) {\n\t\treturn false\n\t}\n\n\toverride hideSelectionBoundsFg(shape: TLBookmarkShape) {\n\t\treturn true\n\t}\n\n\toverride getText(shape: TLBookmarkShape) {\n\t\treturn shape.props.url\n\t}\n\n\toverride getAriaDescriptor(shape: TLBookmarkShape) {\n\t\tconst asset = (\n\t\t\tshape.props.assetId ? this.editor.getAsset(shape.props.assetId) : null\n\t\t) as TLBookmarkAsset | null\n\n\t\tif (!asset?.props.title) return undefined\n\n\t\treturn (\n\t\t\tconvertCommonTitleHTMLEntities(asset.props.title) +\n\t\t\t(asset.props.description ? ', ' + asset.props.description : '')\n\t\t)\n\t}\n\n\toverride getDefaultProps(): TLBookmarkShape['props'] {\n\t\treturn {\n\t\t\turl: '',\n\t\t\tw: BOOKMARK_WIDTH,\n\t\t\th: BOOKMARK_HEIGHT,\n\t\t\tassetId: null,\n\t\t}\n\t}\n\n\toverride getGeometry(shape: TLBookmarkShape) {\n\t\treturn new Rectangle2d({\n\t\t\twidth: shape.props.w,\n\t\t\theight: getBookmarkShapeHeight(this.editor, shape),\n\t\t\tisFilled: true,\n\t\t})\n\t}\n\n\toverride component(shape: TLBookmarkShape) {\n\t\tconst { assetId, url } = shape.props\n\t\tconst h = getBookmarkShapeHeight(this.editor, shape)\n\t\tconst rotation = this.editor.getShapePageTransform(shape)!.rotation()\n\n\t\treturn <BookmarkShapeComponent assetId={assetId} url={url} h={h} rotation={rotation} />\n\t}\n\n\toverride getIndicatorPath(shape: TLBookmarkShape): Path2D {\n\t\tconst path = new Path2D()\n\t\tpath.rect(0, 0, shape.props.w, getBookmarkShapeHeight(this.editor, shape))\n\t\treturn path\n\t}\n\n\toverride onBeforeCreate(next: TLBookmarkShape) {\n\t\treturn setBookmarkHeight(this.editor, next)\n\t}\n\n\toverride onBeforeUpdate(prev: TLBookmarkShape, shape: TLBookmarkShape) {\n\t\tlet next = shape\n\t\tif (prev.props.url !== shape.props.url) {\n\t\t\tif (!T.linkUrl.isValid(shape.props.url)) {\n\t\t\t\treturn { ...shape, props: { ...shape.props, url: prev.props.url } }\n\t\t\t}\n\t\t\tnext = resolveBookmarkAssetForUrlChange(this.editor, shape)\n\t\t}\n\n\t\tif (prev.props.assetId !== next.props.assetId || prev.props.url !== next.props.url) {\n\t\t\treturn setBookmarkHeight(this.editor, next)\n\t\t}\n\n\t\treturn next === shape ? undefined : next\n\t}\n\toverride getInterpolatedProps(\n\t\tstartShape: TLBookmarkShape,\n\t\tendShape: TLBookmarkShape,\n\t\tt: number\n\t): TLBookmarkShapeProps {\n\t\treturn {\n\t\t\t...(t > 0.5 ? endShape.props : startShape.props),\n\t\t\tw: lerp(startShape.props.w, endShape.props.w, t),\n\t\t\th: lerp(startShape.props.h, endShape.props.h, t),\n\t\t}\n\t}\n}\n\nexport function BookmarkShapeComponent({\n\tassetId,\n\trotation,\n\turl,\n\th,\n\tshowImageContainer = true,\n}: {\n\tassetId: TLAssetId | null\n\trotation: number\n\th: number\n\turl: string\n\tshowImageContainer?: boolean\n}) {\n\tconst editor = useEditor()\n\n\tconst resolvedAssetId = getResolvedBookmarkAssetId(editor, assetId, url)\n\tconst asset = resolvedAssetId ? (editor.getAsset(resolvedAssetId) as TLBookmarkAsset) : null\n\n\tconst isSafariExport = !!useSvgExportContext() && tlenv.isSafari\n\n\tconst address = getHumanReadableAddress(url)\n\tconst title = asset ? asset.props.title : isUrlOnlyBookmarkUrl(url) ? url : ''\n\n\tconst [isFaviconValid, setIsFaviconValid] = useState(true)\n\tconst onFaviconError = () => setIsFaviconValid(false)\n\n\tconst markAsHandledOnShiftKey = useCallback<PointerEventHandler>(\n\t\t(e) => {\n\t\t\tif (!editor.inputs.getShiftKey()) editor.markEventAsHandled(e)\n\t\t},\n\t\t[editor]\n\t)\n\n\treturn (\n\t\t<HTMLContainer>\n\t\t\t<div\n\t\t\t\tclassName={classNames(\n\t\t\t\t\t'tl-bookmark__container',\n\t\t\t\t\tisSafariExport && 'tl-bookmark__container--safariExport'\n\t\t\t\t)}\n\t\t\t\tstyle={{\n\t\t\t\t\tboxShadow: isSafariExport ? undefined : getRotatedBoxShadow(rotation),\n\t\t\t\t\tmaxHeight: h,\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{showImageContainer && (asset ? asset.props.image : !isUrlOnlyBookmarkUrl(url)) && (\n\t\t\t\t\t<div className=\"tl-bookmark__image_container\">\n\t\t\t\t\t\t{asset ? (\n\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\tclassName=\"tl-bookmark__image\"\n\t\t\t\t\t\t\t\tdraggable={false}\n\t\t\t\t\t\t\t\treferrerPolicy=\"strict-origin-when-cross-origin\"\n\t\t\t\t\t\t\t\tsrc={asset?.props.image}\n\t\t\t\t\t\t\t\talt={asset?.props.title || ''}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<div className=\"tl-bookmark__placeholder\" />\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{asset?.props.image && <HyperlinkButton url={url} />}\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t\t<div className=\"tl-bookmark__copy_container\">\n\t\t\t\t\t{title ? (\n\t\t\t\t\t\t<a\n\t\t\t\t\t\t\tclassName=\"tl-bookmark__link\"\n\t\t\t\t\t\t\thref={url || ''}\n\t\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\t\trel=\"noopener noreferrer\"\n\t\t\t\t\t\t\tdraggable={false}\n\t\t\t\t\t\t\tonPointerDown={markAsHandledOnShiftKey}\n\t\t\t\t\t\t\tonPointerUp={markAsHandledOnShiftKey}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<h2 className=\"tl-bookmark__heading\">{convertCommonTitleHTMLEntities(title)}</h2>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t) : null}\n\t\t\t\t\t{asset?.props.description && asset?.props.image ? (\n\t\t\t\t\t\t<p className=\"tl-bookmark__description\">{asset.props.description}</p>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<a\n\t\t\t\t\t\tclassName=\"tl-bookmark__link\"\n\t\t\t\t\t\thref={url || ''}\n\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\trel=\"noopener noreferrer\"\n\t\t\t\t\t\tdraggable={false}\n\t\t\t\t\t\tonPointerDown={markAsHandledOnShiftKey}\n\t\t\t\t\t\tonPointerUp={markAsHandledOnShiftKey}\n\t\t\t\t\t>\n\t\t\t\t\t\t{isFaviconValid && asset?.props.favicon ? (\n\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\tclassName=\"tl-bookmark__favicon\"\n\t\t\t\t\t\t\t\tsrc={asset?.props.favicon}\n\t\t\t\t\t\t\t\treferrerPolicy=\"strict-origin-when-cross-origin\"\n\t\t\t\t\t\t\t\tonError={onFaviconError}\n\t\t\t\t\t\t\t\talt={`favicon of ${address}`}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclassName=\"tl-hyperlink__icon\"\n\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\tmask: `url(\"${LINK_ICON}\") center 100% /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ED,4CAAC,UAAM,mBAAQ;AAAA;AAAA;AAAA,UAChB;AAAA,WACD;AAAA;AAAA;AAAA,EACD,GACD;AAEF;",
|
|
6
6
|
"names": ["classNames"]
|
|
7
7
|
}
|
|
@@ -21,11 +21,13 @@ __export(bookmarks_exports, {
|
|
|
21
21
|
BOOKMARK_HEIGHT: () => BOOKMARK_HEIGHT,
|
|
22
22
|
BOOKMARK_JUST_URL_HEIGHT: () => BOOKMARK_JUST_URL_HEIGHT,
|
|
23
23
|
BOOKMARK_WIDTH: () => BOOKMARK_WIDTH,
|
|
24
|
+
SHORT_BOOKMARK_HEIGHT: () => SHORT_BOOKMARK_HEIGHT,
|
|
24
25
|
createBookmarkFromUrl: () => createBookmarkFromUrl,
|
|
25
26
|
getBookmarkHeight: () => getBookmarkHeight,
|
|
26
27
|
getBookmarkShapeHeight: () => getBookmarkShapeHeight,
|
|
27
28
|
getHumanReadableAddress: () => getHumanReadableAddress,
|
|
28
29
|
getResolvedBookmarkAssetId: () => getResolvedBookmarkAssetId,
|
|
30
|
+
isUrlOnlyBookmarkUrl: () => isUrlOnlyBookmarkUrl,
|
|
29
31
|
resolveBookmarkAssetForUrlChange: () => resolveBookmarkAssetForUrlChange,
|
|
30
32
|
setBookmarkHeight: () => setBookmarkHeight
|
|
31
33
|
});
|
|
@@ -35,7 +37,18 @@ const BOOKMARK_WIDTH = 300;
|
|
|
35
37
|
const BOOKMARK_HEIGHT = 320;
|
|
36
38
|
const BOOKMARK_JUST_URL_HEIGHT = 46;
|
|
37
39
|
const SHORT_BOOKMARK_HEIGHT = 101;
|
|
38
|
-
function
|
|
40
|
+
function canUnfurlUrl(url) {
|
|
41
|
+
try {
|
|
42
|
+
const { protocol } = new URL(url);
|
|
43
|
+
return protocol === "http:" || protocol === "https:";
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function isUrlOnlyBookmarkUrl(url) {
|
|
49
|
+
return url !== "" && !canUnfurlUrl(url);
|
|
50
|
+
}
|
|
51
|
+
function getBookmarkHeight(editor, assetId, url) {
|
|
39
52
|
const asset = assetId ? editor.getAsset(assetId) : null;
|
|
40
53
|
if (asset) {
|
|
41
54
|
if (!asset.props.image) {
|
|
@@ -45,18 +58,24 @@ function getBookmarkHeight(editor, assetId) {
|
|
|
45
58
|
return SHORT_BOOKMARK_HEIGHT;
|
|
46
59
|
}
|
|
47
60
|
}
|
|
61
|
+
} else if (isUrlOnlyBookmarkUrl(url)) {
|
|
62
|
+
return SHORT_BOOKMARK_HEIGHT;
|
|
48
63
|
}
|
|
49
64
|
return BOOKMARK_HEIGHT;
|
|
50
65
|
}
|
|
51
66
|
function setBookmarkHeight(editor, shape) {
|
|
52
67
|
return {
|
|
53
68
|
...shape,
|
|
54
|
-
props: {
|
|
69
|
+
props: {
|
|
70
|
+
...shape.props,
|
|
71
|
+
h: getBookmarkHeight(editor, shape.props.assetId, shape.props.url)
|
|
72
|
+
}
|
|
55
73
|
};
|
|
56
74
|
}
|
|
57
75
|
function getHumanReadableAddress(url) {
|
|
58
76
|
try {
|
|
59
77
|
const objUrl = new URL(url);
|
|
78
|
+
if (isUrlOnlyBookmarkUrl(url)) return objUrl.protocol.slice(0, -1);
|
|
60
79
|
return objUrl.hostname.replace(/^www\./, "");
|
|
61
80
|
} catch {
|
|
62
81
|
return url;
|
|
@@ -82,11 +101,12 @@ function getResolvedBookmarkAssetId(editor, assetId, url) {
|
|
|
82
101
|
function getBookmarkShapeHeight(editor, shape) {
|
|
83
102
|
const resolvedAssetId = getResolvedBookmarkAssetId(editor, shape.props.assetId, shape.props.url);
|
|
84
103
|
if (resolvedAssetId === shape.props.assetId) return shape.props.h;
|
|
85
|
-
return getBookmarkHeight(editor, resolvedAssetId);
|
|
104
|
+
return getBookmarkHeight(editor, resolvedAssetId, shape.props.url);
|
|
86
105
|
}
|
|
87
106
|
async function _createBookmarkAssetOnUrlChange(editor, shape) {
|
|
88
107
|
if (editor.isDisposed) return;
|
|
89
108
|
const { url } = shape.props;
|
|
109
|
+
if (!canUnfurlUrl(url)) return;
|
|
90
110
|
const asset = await editor.getAssetForExternalContent({ type: "url", url });
|
|
91
111
|
if (!asset) {
|
|
92
112
|
return;
|
|
@@ -130,7 +150,7 @@ async function createBookmarkFromUrl(editor, {
|
|
|
130
150
|
url,
|
|
131
151
|
assetId: existingAsset?.id ?? null,
|
|
132
152
|
w: BOOKMARK_WIDTH,
|
|
133
|
-
h: getBookmarkHeight(editor, existingAsset?.id)
|
|
153
|
+
h: getBookmarkHeight(editor, existingAsset?.id, url)
|
|
134
154
|
}
|
|
135
155
|
};
|
|
136
156
|
editor.run(() => {
|
|
@@ -150,6 +170,7 @@ async function createBookmarkFromUrl(editor, {
|
|
|
150
170
|
}
|
|
151
171
|
}
|
|
152
172
|
async function hydrateBookmarkShape(editor, shapeId, url) {
|
|
173
|
+
if (!canUnfurlUrl(url)) return;
|
|
153
174
|
let asset;
|
|
154
175
|
try {
|
|
155
176
|
asset = await editor.getAssetForExternalContent({ type: "url", url });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/shapes/bookmark/bookmarks.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tAssetRecordType,\n\tEditor,\n\tResult,\n\tTLAssetId,\n\tTLBookmarkAsset,\n\tTLBookmarkShape,\n\tTLShapeId,\n\tTLShapePartial,\n\tcreateShapeId,\n\tdebounce,\n\tgetHashForString,\n} from '@tldraw/editor'\n\nexport const BOOKMARK_WIDTH = 300\nexport const BOOKMARK_HEIGHT = 320\nexport const BOOKMARK_JUST_URL_HEIGHT = 46\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAYO;AAEA,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AACxB,MAAM,2BAA2B;
|
|
4
|
+
"sourcesContent": ["import {\n\tAssetRecordType,\n\tEditor,\n\tResult,\n\tTLAssetId,\n\tTLBookmarkAsset,\n\tTLBookmarkShape,\n\tTLShapeId,\n\tTLShapePartial,\n\tcreateShapeId,\n\tdebounce,\n\tgetHashForString,\n} from '@tldraw/editor'\n\nexport const BOOKMARK_WIDTH = 300\nexport const BOOKMARK_HEIGHT = 320\nexport const BOOKMARK_JUST_URL_HEIGHT = 46\nexport const SHORT_BOOKMARK_HEIGHT = 101\n\n// A bookmark asset's `src` is a `T.srcUrl`, which rejects app links and `mailto:`. Not\n// `T.httpUrl`: it accepts `''` and relative paths, so clearing a bookmark's url would unfurl.\nfunction canUnfurlUrl(url: string) {\n\ttry {\n\t\tconst { protocol } = new URL(url)\n\t\treturn protocol === 'http:' || protocol === 'https:'\n\t} catch {\n\t\treturn false\n\t}\n}\n\n/**\n * Whether a bookmark without an asset will never get one, rather than still loading. Without\n * this, an app link bookmark shows the loading placeholder forever.\n */\nexport function isUrlOnlyBookmarkUrl(url: string) {\n\treturn url !== '' && !canUnfurlUrl(url)\n}\n\nexport function getBookmarkHeight(\n\teditor: Editor,\n\tassetId: TLAssetId | null | undefined,\n\turl: string\n) {\n\tconst asset = (assetId ? editor.getAsset(assetId) : null) as TLBookmarkAsset | null\n\n\tif (asset) {\n\t\tif (!asset.props.image) {\n\t\t\tif (!asset.props.title) {\n\t\t\t\treturn BOOKMARK_JUST_URL_HEIGHT\n\t\t\t} else {\n\t\t\t\treturn SHORT_BOOKMARK_HEIGHT\n\t\t\t}\n\t\t}\n\t} else if (isUrlOnlyBookmarkUrl(url)) {\n\t\treturn SHORT_BOOKMARK_HEIGHT\n\t}\n\n\treturn BOOKMARK_HEIGHT\n}\n\nexport function setBookmarkHeight(editor: Editor, shape: TLBookmarkShape) {\n\treturn {\n\t\t...shape,\n\t\tprops: {\n\t\t\t...shape.props,\n\t\t\th: getBookmarkHeight(editor, shape.props.assetId, shape.props.url),\n\t\t},\n\t}\n}\n\n/** @internal */\nexport function getHumanReadableAddress(url: string) {\n\ttry {\n\t\tconst objUrl = new URL(url)\n\t\t// An app link's host (`file` in `vscode://file/\u2026`) doesn't say where it goes, but its app does.\n\t\tif (isUrlOnlyBookmarkUrl(url)) return objUrl.protocol.slice(0, -1)\n\t\t// we want the hostname without any www\n\t\treturn objUrl.hostname.replace(/^www\\./, '')\n\t} catch {\n\t\treturn url\n\t}\n}\n\n/**\n * Resolve the asset for a bookmark whose url just changed: the existing asset for the new url\n * if there is one, otherwise `null` while a new one is fetched in the background.\n *\n * Must not write to the store: this runs inside `onBeforeUpdate`, where a nested `updateShapes`\n * is overwritten by the outer put and the old asset would stick.\n */\nexport function resolveBookmarkAssetForUrlChange(\n\teditor: Editor,\n\tshape: TLBookmarkShape\n): TLBookmarkShape {\n\tconst { url } = shape.props\n\n\t// Derive the asset id from the URL\n\tconst assetId: TLAssetId = AssetRecordType.createId(getHashForString(url))\n\n\tif (editor.getAsset(assetId)) {\n\t\tif (shape.props.assetId === assetId) return shape\n\t\treturn { ...shape, props: { ...shape.props, assetId } }\n\t}\n\n\t// No asset for this URL yet: drop the stale reference and fetch one asynchronously\n\tcreateBookmarkAssetOnUrlChange(editor, shape)\n\tif (shape.props.assetId === null) return shape\n\treturn { ...shape, props: { ...shape.props, assetId: null } }\n}\n\n/**\n * Resolve the asset id to render for a bookmark. Bookmark assets are keyed\n * deterministically by URL, so if the shape has no `assetId` but an asset for\n * its URL already exists in the store, use that.\n *\n * This keeps a bookmark from staying stuck on its placeholder after the shape\n * is recreated outside of the hydration flow \u2014 e.g. on redo, where the\n * placeholder is restored with a null `assetId` but its hydrated asset (created\n * with `history: 'ignore'`) still lives in the store.\n */\nexport function getResolvedBookmarkAssetId(\n\teditor: Editor,\n\tassetId: TLAssetId | null,\n\turl: string\n): TLAssetId | null {\n\tif (assetId) return assetId\n\tif (!url) return null\n\n\tconst derivedId: TLAssetId = AssetRecordType.createId(getHashForString(url))\n\treturn editor.getAsset(derivedId) ? derivedId : null\n}\n\n/**\n * The effective height to render and measure a bookmark at.\n *\n * Normally this is the stored `props.h`. But when the shape's `assetId` resolves\n * to a different asset than it stores \u2014 e.g. a placeholder restored on redo with\n * a null `assetId` whose asset already exists in the store \u2014 `props.h` is stale\n * (it still holds the placeholder height). In that case recompute the height\n * from the resolved asset so rendering, the indicator, and the geometry/selection\n * bounds all stay in sync.\n */\nexport function getBookmarkShapeHeight(editor: Editor, shape: TLBookmarkShape): number {\n\tconst resolvedAssetId = getResolvedBookmarkAssetId(editor, shape.props.assetId, shape.props.url)\n\tif (resolvedAssetId === shape.props.assetId) return shape.props.h\n\treturn getBookmarkHeight(editor, resolvedAssetId, shape.props.url)\n}\n\nasync function _createBookmarkAssetOnUrlChange(editor: Editor, shape: TLBookmarkShape) {\n\tif (editor.isDisposed) return\n\n\tconst { url } = shape.props\n\tif (!canUnfurlUrl(url)) return\n\n\t// Create the asset using the external content manager's createAssetFromUrl method.\n\t// This may be overwritten by the user (for example, we overwrite it on tldraw.com)\n\tconst asset = await editor.getAssetForExternalContent({ type: 'url', url })\n\n\tif (!asset) {\n\t\t// No asset? Just leave the bookmark as a null assetId.\n\t\treturn\n\t}\n\n\teditor.run(() => {\n\t\t// Create the new asset\n\t\teditor.createAssets([asset])\n\n\t\t// And update the shape\n\t\teditor.updateShapes([\n\t\t\t{\n\t\t\t\tid: shape.id,\n\t\t\t\ttype: shape.type,\n\t\t\t\tprops: { assetId: asset.id },\n\t\t\t},\n\t\t])\n\t})\n}\n\nconst bookmarkDebouncers = new WeakMap<\n\tEditor,\n\tReturnType<typeof debounce<[Editor, TLBookmarkShape], void>>\n>()\n\nfunction createBookmarkAssetOnUrlChange(editor: Editor, shape: TLBookmarkShape) {\n\tlet fn = bookmarkDebouncers.get(editor)\n\tif (!fn) {\n\t\tfn = debounce(_createBookmarkAssetOnUrlChange, 500)\n\t\tbookmarkDebouncers.set(editor, fn)\n\t}\n\tfn(editor, shape)\n}\n\n/**\n * Creates a bookmark shape from a URL.\n *\n * The shape is created immediately as a placeholder so the user gets visible\n * feedback at the paste location, and the bookmark metadata (title, description,\n * image, favicon) is fetched in the background. Once metadata resolves, the\n * shape is patched with the resulting asset. If the fetch fails, the shape is\n * left as a URL-only bookmark.\n *\n * @returns A Result containing the created bookmark shape or an error\n * @public\n */\nexport async function createBookmarkFromUrl(\n\teditor: Editor,\n\t{\n\t\turl,\n\t\tcenter = editor.getViewportPageBounds().center,\n\t}: {\n\t\turl: string\n\t\tcenter?: { x: number; y: number }\n\t}\n): Promise<Result<TLBookmarkShape, string>> {\n\ttry {\n\t\t// If we already have a bookmark asset for this URL (e.g. another bookmark\n\t\t// shape was created from the same URL earlier), use it immediately rather\n\t\t// than re-fetching.\n\t\tconst expectedAssetId: TLAssetId = AssetRecordType.createId(getHashForString(url))\n\t\tconst existingAsset = editor.getAsset(expectedAssetId) as TLBookmarkAsset | null\n\n\t\tconst shapeId = createShapeId()\n\t\tconst shapePartial: TLShapePartial<TLBookmarkShape> = {\n\t\t\tid: shapeId,\n\t\t\ttype: 'bookmark',\n\t\t\tx: center.x - BOOKMARK_WIDTH / 2,\n\t\t\ty: center.y - BOOKMARK_HEIGHT / 2,\n\t\t\trotation: 0,\n\t\t\topacity: 1,\n\t\t\tprops: {\n\t\t\t\turl,\n\t\t\t\tassetId: existingAsset?.id ?? null,\n\t\t\t\tw: BOOKMARK_WIDTH,\n\t\t\t\th: getBookmarkHeight(editor, existingAsset?.id, url),\n\t\t\t},\n\t\t}\n\n\t\teditor.run(() => {\n\t\t\teditor.createShapes([shapePartial])\n\t\t})\n\n\t\tconst createdShape = editor.getShape<TLBookmarkShape>(shapeId)\n\t\tif (!createdShape) {\n\t\t\treturn Result.err('Failed to create bookmark shape')\n\t\t}\n\n\t\t// If we already had the asset, we're done \u2014 no metadata fetch needed.\n\t\tif (existingAsset) {\n\t\t\treturn Result.ok(createdShape)\n\t\t}\n\n\t\t// Otherwise kick off the metadata fetch in the background. The shape is\n\t\t// already visible as a placeholder; once the asset resolves we'll patch\n\t\t// the shape with its assetId.\n\t\tvoid hydrateBookmarkShape(editor, shapeId, url)\n\n\t\treturn Result.ok(createdShape)\n\t} catch (error) {\n\t\treturn Result.err(error instanceof Error ? error.message : 'Failed to create bookmark')\n\t}\n}\n\nasync function hydrateBookmarkShape(editor: Editor, shapeId: TLShapeId, url: string) {\n\tif (!canUnfurlUrl(url)) return\n\n\tlet asset\n\ttry {\n\t\tasset = await editor.getAssetForExternalContent({ type: 'url', url })\n\t} catch (error) {\n\t\tconsole.error(error)\n\t\treturn\n\t}\n\n\tif (editor.isDisposed) return\n\tif (!asset) return\n\n\t// The shape may have been deleted (e.g. via undo), had its URL changed, or\n\t// had its asset replaced before the fetch resolved. In any of those cases we\n\t// don't want to attach metadata for the old URL.\n\tconst shape = editor.getShape<TLBookmarkShape>(shapeId)\n\tif (!shape) return\n\tif (shape.props.url !== url) return\n\tif (shape.props.assetId) return\n\n\teditor.run(\n\t\t() => {\n\t\t\tif (!editor.getAsset(asset.id)) {\n\t\t\t\teditor.createAssets([asset])\n\t\t\t}\n\t\t\teditor.updateShapes([\n\t\t\t\t{\n\t\t\t\t\tid: shapeId,\n\t\t\t\t\ttype: 'bookmark',\n\t\t\t\t\tprops: { assetId: asset.id },\n\t\t\t\t},\n\t\t\t])\n\t\t},\n\t\t{ history: 'ignore' }\n\t)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAYO;AAEA,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AACxB,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAIrC,SAAS,aAAa,KAAa;AAClC,MAAI;AACH,UAAM,EAAE,SAAS,IAAI,IAAI,IAAI,GAAG;AAChC,WAAO,aAAa,WAAW,aAAa;AAAA,EAC7C,QAAQ;AACP,WAAO;AAAA,EAC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C,MAAO;AACZ,MAAI,MAAM,MAAM,QAAQ,IAAK;AAC7B,MAAI,MAAM,MAAM,QAAS;AAEzB,SAAO;AAAA,IACN,MAAM;AACL,UAAI,CAAC,OAAO,SAAS,MAAM,EAAE,GAAG;AAC/B,eAAO,aAAa,CAAC,KAAK,CAAC;AAAA,MAC5B;AACA,aAAO,aAAa;AAAA,QACnB;AAAA,UACC,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,OAAO,EAAE,SAAS,MAAM,GAAG;AAAA,QAC5B;AAAA,MACD,CAAC;AAAA,IACF;AAAA,IACA,EAAE,SAAS,SAAS;AAAA,EACrB;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -25,25 +25,16 @@ module.exports = __toCommonJS(EditLinkDialog_exports);
|
|
|
25
25
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
26
|
var import_editor = require("@tldraw/editor");
|
|
27
27
|
var import_react = require("react");
|
|
28
|
+
var import_linkUrl = require("../../utils/linkUrl");
|
|
28
29
|
var import_shapes = require("../../utils/shapes/shapes");
|
|
29
30
|
var import_i18n = require("../context/i18n");
|
|
30
31
|
var import_TldrawUiButton = require("./primitives/Button/TldrawUiButton");
|
|
31
32
|
var import_TldrawUiButtonLabel = require("./primitives/Button/TldrawUiButtonLabel");
|
|
32
33
|
var import_TldrawUiDialog = require("./primitives/TldrawUiDialog");
|
|
33
34
|
var import_TldrawUiInput = require("./primitives/TldrawUiInput");
|
|
34
|
-
function validateUrl(url) {
|
|
35
|
-
if (import_editor.T.linkUrl.isValid(url)) {
|
|
36
|
-
return { isValid: true, hasProtocol: true };
|
|
37
|
-
}
|
|
38
|
-
if (import_editor.T.linkUrl.isValid("https://" + url)) {
|
|
39
|
-
return { isValid: true, hasProtocol: false };
|
|
40
|
-
}
|
|
41
|
-
return { isValid: false, hasProtocol: false };
|
|
42
|
-
}
|
|
43
35
|
function getUrlInputState(url) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
return { actual: url, safe, valid: isValid };
|
|
36
|
+
const normalized = (0, import_linkUrl.normalizeLinkUrl)(url);
|
|
37
|
+
return { actual: url, safe: normalized ?? "", valid: normalized !== null };
|
|
47
38
|
}
|
|
48
39
|
function assertShapeWithLink(shape) {
|
|
49
40
|
if (!(0, import_shapes.isShapeWithLink)(shape)) {
|
|
@@ -80,9 +71,10 @@ const EditLinkDialogInner = (0, import_editor.track)(function EditLinkDialogInne
|
|
|
80
71
|
const { safe } = getUrlInputState(selectedShape.props.url);
|
|
81
72
|
return { actual: safe, safe, valid: true };
|
|
82
73
|
});
|
|
74
|
+
const [showInvalid, setShowInvalid] = (0, import_react.useState)(false);
|
|
83
75
|
const handleChange = (0, import_react.useCallback)((rawValue) => {
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
setUrlInputState(getUrlInputState(rawValue));
|
|
77
|
+
setShowInvalid(false);
|
|
86
78
|
}, []);
|
|
87
79
|
const handleClear = (0, import_react.useCallback)(() => {
|
|
88
80
|
const onlySelectedShape = editor.getOnlySelectedShape();
|
|
@@ -97,6 +89,11 @@ const EditLinkDialogInner = (0, import_editor.track)(function EditLinkDialogInne
|
|
|
97
89
|
const onlySelectedShape = editor.getOnlySelectedShape();
|
|
98
90
|
if (!onlySelectedShape) return;
|
|
99
91
|
assertShapeWithLink(onlySelectedShape);
|
|
92
|
+
if (!urlInputState.valid) {
|
|
93
|
+
setShowInvalid(true);
|
|
94
|
+
rInput.current?.focus();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
100
97
|
if (onlySelectedShape.props.url !== urlInputState.safe) {
|
|
101
98
|
editor.updateShapes([
|
|
102
99
|
{
|
|
@@ -111,7 +108,8 @@ const EditLinkDialogInner = (0, import_editor.track)(function EditLinkDialogInne
|
|
|
111
108
|
const handleCancel = (0, import_react.useCallback)(() => {
|
|
112
109
|
onClose();
|
|
113
110
|
}, [onClose]);
|
|
114
|
-
const
|
|
111
|
+
const isEmpty = urlInputState.valid && urlInputState.safe === "";
|
|
112
|
+
const isRemoving = !!rInitialValue.current && isEmpty;
|
|
115
113
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
116
114
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_TldrawUiDialog.TldrawUiDialogHeader, { children: [
|
|
117
115
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiDialog.TldrawUiDialogTitle, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_i18n.F, { defaultMessage: "Edit link", id: "edit-link-dialog.title" }) }),
|
|
@@ -133,7 +131,7 @@ const EditLinkDialogInner = (0, import_editor.track)(function EditLinkDialogInne
|
|
|
133
131
|
onCancel: handleCancel
|
|
134
132
|
}
|
|
135
133
|
),
|
|
136
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children:
|
|
134
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: showInvalid ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_i18n.F, { defaultMessage: "A link must be a valid URL.", id: "edit-link-dialog.invalid-url" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_i18n.F, { defaultMessage: "Links will open in a new tab.", id: "edit-link-dialog.detail" }) })
|
|
137
135
|
] }) }),
|
|
138
136
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_TldrawUiDialog.TldrawUiDialogFooter, { className: "tlui-dialog__footer__actions", children: [
|
|
139
137
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiButton.TldrawUiButton, { type: "normal", onClick: handleCancel, onTouchEnd: handleCancel, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiButtonLabel.TldrawUiButtonLabel, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_i18n.F, { defaultMessage: "Cancel", id: "edit-link-dialog.cancel" }) }) }),
|
|
@@ -141,7 +139,7 @@ const EditLinkDialogInner = (0, import_editor.track)(function EditLinkDialogInne
|
|
|
141
139
|
import_TldrawUiButton.TldrawUiButton,
|
|
142
140
|
{
|
|
143
141
|
type: "primary",
|
|
144
|
-
disabled: !urlInputState.valid,
|
|
142
|
+
disabled: !urlInputState.valid || isEmpty,
|
|
145
143
|
onTouchEnd: handleComplete,
|
|
146
144
|
onClick: handleComplete,
|
|
147
145
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiButtonLabel.TldrawUiButtonLabel, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_i18n.F, { defaultMessage: "Continue", id: "edit-link-dialog.save" }) })
|