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
|
@@ -20,14 +20,14 @@ const components: TLComponents = {
|
|
|
20
20
|
|
|
21
21
|
const shapeId = createShapeId('box')
|
|
22
22
|
|
|
23
|
-
async function renderWithOpenDialog() {
|
|
23
|
+
async function renderWithOpenDialog(url = 'https://tldraw.com') {
|
|
24
24
|
const { editor } = await renderTldrawComponentWithEditor(
|
|
25
25
|
(onMount) => <Tldraw components={components} onMount={onMount} />,
|
|
26
26
|
{ waitForPatterns: false }
|
|
27
27
|
)
|
|
28
28
|
|
|
29
29
|
act(() => {
|
|
30
|
-
editor.createShape({ id: shapeId, type: 'geo', props: { url
|
|
30
|
+
editor.createShape({ id: shapeId, type: 'geo', props: { url } })
|
|
31
31
|
editor.select(shapeId)
|
|
32
32
|
})
|
|
33
33
|
|
|
@@ -75,3 +75,54 @@ it('closes itself when the shape is deselected while the dialog is open', async
|
|
|
75
75
|
|
|
76
76
|
await expectDialogClosed()
|
|
77
77
|
})
|
|
78
|
+
|
|
79
|
+
function submitLink(value: string) {
|
|
80
|
+
const input = document.querySelector('.tlui-edit-link-dialog__input') as HTMLInputElement
|
|
81
|
+
fireEvent.change(input, { target: { value } })
|
|
82
|
+
fireEvent.keyDown(input, { key: 'Enter' })
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
it.each([
|
|
86
|
+
['example.com', 'https://example.com'],
|
|
87
|
+
['', ''],
|
|
88
|
+
])('saves %j as %j', async (input, expected) => {
|
|
89
|
+
editor = await renderWithOpenDialog()
|
|
90
|
+
act(() => submitLink(input))
|
|
91
|
+
await expectDialogClosed()
|
|
92
|
+
expect(editor.getShape(shapeId)!.props).toMatchObject({ url: expected })
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it.each(['https://tldraw.com', ''])(
|
|
96
|
+
'does not save an invalid url on enter when the link was %j',
|
|
97
|
+
async (url) => {
|
|
98
|
+
editor = await renderWithOpenDialog(url)
|
|
99
|
+
act(() => submitLink('hello'))
|
|
100
|
+
await act(async () => {})
|
|
101
|
+
expect(getDialogFrame()).not.toBeNull()
|
|
102
|
+
expect(screen.getByText('A link must be a valid URL.')).toBeTruthy()
|
|
103
|
+
expect(editor.getShape(shapeId)!.props).toMatchObject({ url })
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
function getSubmitButton() {
|
|
108
|
+
const footer = document.querySelector('.tlui-dialog__footer__actions')!
|
|
109
|
+
const buttons = footer.querySelectorAll('button')
|
|
110
|
+
const button = buttons[buttons.length - 1]
|
|
111
|
+
return { label: button.textContent, disabled: button.disabled }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
it.each([
|
|
115
|
+
['', '', { label: 'Continue', disabled: true }],
|
|
116
|
+
['', 'example.com', { label: 'Continue', disabled: false }],
|
|
117
|
+
['', 'hello', { label: 'Continue', disabled: true }],
|
|
118
|
+
['https://tldraw.com', '', { label: 'Clear', disabled: false }],
|
|
119
|
+
['https://tldraw.com', 'example.com', { label: 'Continue', disabled: false }],
|
|
120
|
+
['https://tldraw.com', 'hello', { label: 'Continue', disabled: true }],
|
|
121
|
+
])('with link %j and input %j, the submit button is %j', async (url, input, expected) => {
|
|
122
|
+
editor = await renderWithOpenDialog(url)
|
|
123
|
+
const field = document.querySelector('.tlui-edit-link-dialog__input') as HTMLInputElement
|
|
124
|
+
act(() => {
|
|
125
|
+
fireEvent.change(field, { target: { value: input } })
|
|
126
|
+
})
|
|
127
|
+
expect(getSubmitButton()).toEqual(expected)
|
|
128
|
+
})
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { act, fireEvent } from '@testing-library/react'
|
|
2
|
+
import { Editor as TextEditor } from '@tiptap/core'
|
|
3
|
+
import { Tldraw } from '../../lib/Tldraw'
|
|
4
|
+
import { LinkEditor } from '../../lib/ui/components/Toolbar/LinkEditor'
|
|
5
|
+
import { tipTapDefaultExtensions } from '../../lib/utils/text/richText'
|
|
6
|
+
import { renderTldrawComponent } from '../testutils/renderTldrawComponent'
|
|
7
|
+
|
|
8
|
+
let textEditor: TextEditor
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
textEditor?.destroy()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
// The real toolbar only mounts while editing a shape with a non-collapsed selection, which jsdom
|
|
15
|
+
// can't lay out, so the link editor is rendered directly against a standalone TipTap editor.
|
|
16
|
+
async function renderLinkEditor() {
|
|
17
|
+
textEditor = new TextEditor({
|
|
18
|
+
element: document.createElement('div'),
|
|
19
|
+
extensions: tipTapDefaultExtensions,
|
|
20
|
+
enableCoreExtensions: { textDirection: false },
|
|
21
|
+
content: 'hello',
|
|
22
|
+
})
|
|
23
|
+
textEditor.commands.selectAll()
|
|
24
|
+
const onClose = vi.fn()
|
|
25
|
+
|
|
26
|
+
await renderTldrawComponent(
|
|
27
|
+
<Tldraw
|
|
28
|
+
components={{
|
|
29
|
+
TopPanel: () => <LinkEditor textEditor={textEditor} value="" onClose={onClose} />,
|
|
30
|
+
}}
|
|
31
|
+
/>,
|
|
32
|
+
{ waitForPatterns: false }
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const input = document.querySelector('[data-testid="rich-text.link-input"]') as HTMLInputElement
|
|
36
|
+
return {
|
|
37
|
+
onClose,
|
|
38
|
+
type: (value: string) => act(() => fireEvent.change(input, { target: { value } })),
|
|
39
|
+
pressEnter: () => act(() => fireEvent.keyDown(input, { key: 'Enter' })),
|
|
40
|
+
isMarkedInvalid: () => input.classList.contains('tlui-rich-text__toolbar-link-input--invalid'),
|
|
41
|
+
getHref: () => {
|
|
42
|
+
textEditor.commands.selectAll()
|
|
43
|
+
return textEditor.getAttributes('link').href
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
it.each([
|
|
49
|
+
['codex://threads/abc-123', 'codex://threads/abc-123'],
|
|
50
|
+
['example.com', 'https://example.com'],
|
|
51
|
+
])('links %j as %j', async (input, expected) => {
|
|
52
|
+
const linkEditor = await renderLinkEditor()
|
|
53
|
+
linkEditor.type(input)
|
|
54
|
+
linkEditor.pressEnter()
|
|
55
|
+
expect(linkEditor.getHref()).toBe(expected)
|
|
56
|
+
expect(linkEditor.onClose).toHaveBeenCalled()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('marks an invalid url only once enter is pressed, and stays open without linking', async () => {
|
|
60
|
+
const linkEditor = await renderLinkEditor()
|
|
61
|
+
linkEditor.type('hello')
|
|
62
|
+
expect(linkEditor.isMarkedInvalid()).toBe(false)
|
|
63
|
+
|
|
64
|
+
linkEditor.pressEnter()
|
|
65
|
+
expect(linkEditor.isMarkedInvalid()).toBe(true)
|
|
66
|
+
expect(linkEditor.getHref()).toBeUndefined()
|
|
67
|
+
expect(linkEditor.onClose).not.toHaveBeenCalled()
|
|
68
|
+
|
|
69
|
+
linkEditor.type('hello.com')
|
|
70
|
+
expect(linkEditor.isMarkedInvalid()).toBe(false)
|
|
71
|
+
})
|
package/tldraw.css
CHANGED
|
@@ -3886,12 +3886,19 @@ tldraw? probably.
|
|
|
3886
3886
|
}
|
|
3887
3887
|
|
|
3888
3888
|
.tlui-rich-text__toolbar-link-input {
|
|
3889
|
-
margin
|
|
3889
|
+
/* Padding rather than margin, so the invalid outline runs to the toolbar's left edge. */
|
|
3890
|
+
padding-left: 12px;
|
|
3890
3891
|
/*
|
|
3891
3892
|
* Nice touch tweak: keep the link editor toolbar the same as the default toolbar.
|
|
3892
3893
|
* This is so the toolbar size stays stable going in and out of the link editor.
|
|
3893
3894
|
*/
|
|
3894
|
-
width:
|
|
3895
|
+
width: 160px;
|
|
3896
|
+
}
|
|
3897
|
+
|
|
3898
|
+
.tlui-rich-text__toolbar-link-input--invalid {
|
|
3899
|
+
/* An inset shadow rather than a border, so the input doesn't change size. */
|
|
3900
|
+
box-shadow: inset 0 0 0 1px var(--tl-color-danger);
|
|
3901
|
+
border-radius: var(--tl-radius-3) var(--tl-radius-2) var(--tl-radius-2) var(--tl-radius-3);
|
|
3895
3902
|
}
|
|
3896
3903
|
|
|
3897
3904
|
.tlui-media__toolbar-alt-text-input {
|