tldraw 4.2.0-next.bfd9ab728a80 → 4.2.0-next.bff7e3992d58

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 (58) hide show
  1. package/dist-cjs/index.d.ts +2 -1
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/lib/shapes/frame/components/FrameLabelInput.js +63 -36
  4. package/dist-cjs/lib/shapes/frame/components/FrameLabelInput.js.map +2 -2
  5. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +3 -3
  6. package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
  7. package/dist-cjs/lib/shapes/shared/ShapeFill.js +3 -0
  8. package/dist-cjs/lib/shapes/shared/ShapeFill.js.map +2 -2
  9. package/dist-cjs/lib/ui/components/Dialogs.js +2 -14
  10. package/dist-cjs/lib/ui/components/Dialogs.js.map +2 -2
  11. package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js +5 -4
  12. package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js.map +2 -2
  13. package/dist-cjs/lib/ui/components/primitives/Button/TldrawUiButton.js +2 -2
  14. package/dist-cjs/lib/ui/components/primitives/Button/TldrawUiButton.js.map +2 -2
  15. package/dist-cjs/lib/ui/context/actions.js +16 -0
  16. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  17. package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
  18. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +1 -0
  19. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +2 -2
  20. package/dist-cjs/lib/ui/hooks/useTranslation/useTranslation.js +1 -0
  21. package/dist-cjs/lib/ui/hooks/useTranslation/useTranslation.js.map +2 -2
  22. package/dist-cjs/lib/ui/version.js +3 -3
  23. package/dist-cjs/lib/ui/version.js.map +1 -1
  24. package/dist-esm/index.d.mts +2 -1
  25. package/dist-esm/index.mjs +1 -1
  26. package/dist-esm/lib/shapes/frame/components/FrameLabelInput.mjs +65 -38
  27. package/dist-esm/lib/shapes/frame/components/FrameLabelInput.mjs.map +2 -2
  28. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +5 -5
  29. package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
  30. package/dist-esm/lib/shapes/shared/ShapeFill.mjs +3 -0
  31. package/dist-esm/lib/shapes/shared/ShapeFill.mjs.map +2 -2
  32. package/dist-esm/lib/ui/components/Dialogs.mjs +2 -14
  33. package/dist-esm/lib/ui/components/Dialogs.mjs.map +2 -2
  34. package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs +5 -5
  35. package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs.map +2 -2
  36. package/dist-esm/lib/ui/components/primitives/Button/TldrawUiButton.mjs +2 -2
  37. package/dist-esm/lib/ui/components/primitives/Button/TldrawUiButton.mjs.map +2 -2
  38. package/dist-esm/lib/ui/context/actions.mjs +16 -0
  39. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  40. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +1 -0
  41. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +2 -2
  42. package/dist-esm/lib/ui/hooks/useTranslation/useTranslation.mjs +1 -0
  43. package/dist-esm/lib/ui/hooks/useTranslation/useTranslation.mjs.map +2 -2
  44. package/dist-esm/lib/ui/version.mjs +3 -3
  45. package/dist-esm/lib/ui/version.mjs.map +1 -1
  46. package/package.json +3 -3
  47. package/src/lib/shapes/frame/components/FrameLabelInput.tsx +48 -24
  48. package/src/lib/shapes/note/NoteShapeUtil.tsx +6 -5
  49. package/src/lib/shapes/shared/ShapeFill.tsx +3 -0
  50. package/src/lib/ui/components/Dialogs.tsx +2 -14
  51. package/src/lib/ui/components/PageMenu/DefaultPageMenu.tsx +6 -5
  52. package/src/lib/ui/components/primitives/Button/TldrawUiButton.tsx +3 -2
  53. package/src/lib/ui/context/actions.tsx +16 -0
  54. package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +1 -0
  55. package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +1 -0
  56. package/src/lib/ui/hooks/useTranslation/useTranslation.tsx +2 -1
  57. package/src/lib/ui/version.ts +3 -3
  58. package/src/test/TldrawEditor.test.tsx +74 -29
@@ -6,16 +6,17 @@ import {
6
6
  HTMLContainer,
7
7
  TLAssetStore,
8
8
  TLBaseShape,
9
+ TLShapeId,
9
10
  TldrawEditor,
10
11
  createShapeId,
11
12
  createTLStore,
12
13
  noop,
14
+ toRichText,
13
15
  } from '@tldraw/editor'
14
16
  import { StrictMode } from 'react'
15
17
  import { vi } from 'vitest'
16
18
  import { defaultShapeUtils } from '../lib/defaultShapeUtils'
17
19
  import { defaultTools } from '../lib/defaultTools'
18
- import { GeoShapeUtil } from '../lib/shapes/geo/GeoShapeUtil'
19
20
  import { defaultAddFontsFromNode, tipTapDefaultExtensions } from '../lib/utils/text/richText'
20
21
  import {
21
22
  renderTldrawComponent,
@@ -169,7 +170,7 @@ describe('<TldrawEditor />', () => {
169
170
  let editor = {} as Editor
170
171
  await renderTldrawComponent(
171
172
  <TldrawEditor
172
- shapeUtils={[GeoShapeUtil]}
173
+ shapeUtils={defaultShapeUtils}
173
174
  initialState="select"
174
175
  tools={defaultTools}
175
176
  onMount={(editorApp) => {
@@ -185,39 +186,83 @@ describe('<TldrawEditor />', () => {
185
186
  editor.updateInstanceState({ screenBounds: { x: 0, y: 0, w: 1080, h: 720 } })
186
187
  })
187
188
 
188
- const id = createShapeId()
189
-
190
- await act(async () => {
191
- editor.createShapes([
192
- {
193
- id,
194
- type: 'geo',
195
- props: { w: 100, h: 100 },
189
+ // Test all shape types except group
190
+ const shapeTypesToTest = [
191
+ { type: 'arrow' as const, props: { start: { x: 0, y: 0 }, end: { x: 100, y: 100 } } },
192
+ { type: 'bookmark' as const, props: { w: 100, h: 100, url: 'https://example.com' } },
193
+ {
194
+ type: 'draw' as const,
195
+ props: { segments: [{ type: 'free' as const, points: [{ x: 0, y: 0, z: 0.5 }] }] },
196
+ },
197
+ { type: 'embed' as const, props: { w: 100, h: 100, url: 'https://example.com' } },
198
+ { type: 'frame' as const, props: { w: 100, h: 100 } },
199
+ { type: 'geo' as const, props: { w: 100, h: 100, geo: 'rectangle' } },
200
+ {
201
+ type: 'highlight' as const,
202
+ props: { segments: [{ type: 'free' as const, points: [{ x: 0, y: 0, z: 0.5 }] }] },
203
+ },
204
+ { type: 'image' as const, props: { w: 100, h: 100 } },
205
+ {
206
+ type: 'line' as const,
207
+ props: {
208
+ points: {
209
+ a1: { id: 'a1', index: 'a1', x: 0, y: 0 },
210
+ a2: { id: 'a2', index: 'a2', x: 100, y: 100 },
211
+ },
196
212
  },
197
- ])
198
- })
213
+ },
214
+ { type: 'note' as const, props: { richText: toRichText('test') } },
215
+ { type: 'text' as const, props: { w: 100, richText: toRichText('test') } },
216
+ { type: 'video' as const, props: { w: 100, h: 100 } },
217
+ ]
218
+
219
+ const shapeIds: TLShapeId[] = []
220
+
221
+ for (let i = 0; i < shapeTypesToTest.length; i++) {
222
+ const shapeConfig = shapeTypesToTest[i]
223
+ const id = createShapeId()
224
+ shapeIds.push(id)
225
+
226
+ await act(async () => {
227
+ editor.createShapes([
228
+ {
229
+ id,
230
+ type: shapeConfig.type,
231
+ x: i * 150, // Space them out horizontally
232
+ y: 0,
233
+ props: shapeConfig.props,
234
+ },
235
+ ])
236
+ })
237
+
238
+ // Does the shape exist?
239
+ const shape = editor.getShape(id)
240
+ expect(shape).toBeTruthy()
241
+ expect(shape?.type).toBe(shapeConfig.type)
242
+
243
+ // Check that all shapes rendered without error boundaries
244
+ expect(
245
+ document.querySelectorAll('.tl-shape-error-boundary'),
246
+ `${shapeConfig.type} had an error while rendering`
247
+ ).toHaveLength(0)
248
+ }
199
249
 
200
- // Does the shape exist?
201
- expect(editor.getShape(id)).toMatchObject({
202
- id,
203
- type: 'geo',
204
- x: 0,
205
- y: 0,
206
- opacity: 1,
207
- props: { geo: 'rectangle', w: 100, h: 100 },
208
- })
250
+ // Check that all shape components are rendering
251
+ expect(document.querySelectorAll('.tl-shape').length).toBeGreaterThanOrEqual(
252
+ shapeTypesToTest.length
253
+ )
209
254
 
210
- // Is the shape's component rendering?
211
- expect(document.querySelectorAll('.tl-shape')).toHaveLength(1)
212
- // though indicator should be display none
213
- expect(document.querySelectorAll('.tl-shape-indicator')).toHaveLength(1)
255
+ // Check that all shape indicators are present
256
+ expect(document.querySelectorAll('.tl-shape-indicator').length).toBeGreaterThanOrEqual(
257
+ shapeTypesToTest.length
258
+ )
214
259
 
215
- // Select the shape
216
- await act(async () => editor.select(id))
260
+ // Select one of the shapes (the note shape)
261
+ const noteShapeId = shapeIds[9] // note is at index 9
262
+ await act(async () => editor.select(noteShapeId))
217
263
 
218
264
  expect(editor.getSelectedShapeIds().length).toBe(1)
219
- // though indicator it should be visible
220
- expect(document.querySelectorAll('.tl-shape-indicator')).toHaveLength(1)
265
+ expect(editor.getSelectedShapeIds()[0]).toBe(noteShapeId)
221
266
 
222
267
  // Select the eraser tool...
223
268
  await act(async () => editor.setCurrentTool('eraser'))