Commit 6230dc7
authored
Augmentation-based shape and binding types (tldraw#7091)
continues the work done in tldraw#6739
### Change type
- [ ] `bugfix`
- [x] `improvement`
- [ ] `feature`
- [ ] `api`
- [ ] `other`
### Test plan
1. Tested manually in
https://github.com/Andarist/tldraw-augmentation-test
2. The most complex `TLIndexedShapes` also tested manually in [TS
playground](https://www.typescriptlang.org/play/?ts=6.0.0-dev.20251027#code/JYOwLgpgTgZghgYwgAgCoBkBCcDOEDKAFnAA4QA8qAnmQDTIAKUA9iTgHzIDeAUMsmBoQAXGiEBuPshIs2opqxySAvjx6CyadAEEoLAO5FSKALxbseI2XIAiOHub6b9LsgAmwKKJxgooAObIyuySGigYmMwAHlam5rgExNY2AEbRztzIUaIgAK4AtinQ4shUOQVFUEEh6kJaAML2brHIZhEJsbYITRmuCMwANsxeyD5+IIHBoXUYAOIsuSQtbVgdSRQ2-gskvcjAbt6+AdXTmhgAavsQzMvxluu2AG5XzLtgwPkiyHmFxdIDcCoAVEaUGEDgIBOajCWgAIhB4LkBmBllIAD5aXQGWLo8zRHH8DEYRpQZrrXFzbYE5BE9CXNzXWKSHgQKIkYZgPbgaDwJBaWZDFJwAaxBRsACypG4qhZbI5XMgsEQ4XQAuYQpF6zFOElJG4Um6pPKAwGJQA9GbkKyEANcgzkPpgGBCMh4AMcFQDbkfMx8qJXEKAF4BOCHcaTc2W1mQEBuB1Ol1wZD9fIkAYQSADKjJ71gX2jcn8Z4M5j+gQfL4-SolNOA4HIUHpiElYVgVDRsPHZSRq1RGNxhmI5EF4xSLbMRbG03IC17MAAchwyCT-SgKBw63oTuTEPnnKK7mAODgKXTbjNzEe0D8DJAPBlrPZUE5MIwAElY6yIGTjEuzLx+FnAB1FAnWgOBIGQS9oGXZBchAYBmEhZgYGXXJ-E+bk4wAawgKglwhAcETgJFOQ3YwBCEHAADopFnVBCCPZcTUcJdvQEZguRtO0UAACmGZMkI8d4kOFLNe24+0BOgvQrgASgEQgUEHEjh3Isgl1AKCQBQfxmFowCzToy0P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IfniulWAjJcr7ItzICK0V6SVJqWamsSQvFRX3L1Q6UVzlmCiExUcaVpqFXmF4gAKhxp2O1P40Tqo1W5d4VRvhQCNe69JUy-IBVBCAX1frjJkjCrFHVjhQ3pMNW6hmS5KRxGaNFGmKAar6ATc+c1H4GSIjTU6Z8PLVC8V4gSHMP98C4pCKgZAxA-TIAdWkIpFhnWngsEAA))
### Description
The main goal of this PR is to allow users to provide users to strictly
type all their custom shapes' props.
Previously people would have to resort to using an unknown shape,
casting, or "casting" through generics (where tldraw types would just
accept their type arguments happily). With the new system in place users
can augment a builtin tldraw interface like this:
```ts
const CIRCLE_CLIP_TYPE = 'circle-clip'
declare module 'tldraw' {
export interface TLGlobalShapePropsMap {
[CIRCLE_CLIP_TYPE]: {
w: number
h: number
}
}
}
export type CircleClipShape = TLShape<typeof CIRCLE_CLIP_TYPE>
```
Once this is done, users can now use the shape type like this:
```ts
editor.updateShape({
id: shapeId,
type: 'circle-clip',
props: {
w: 100,
h: 100,
},
})
```
Thanks to the power of discriminated unions, this will now error if the
user tries to update the shape with the wrong props.
That said, for the time-being, I kept generic parameters in the editor
methods to:
- maintain backwards compatibility
- keep this documented pattern working:
https://tldraw.dev/docs/shapes#Meta-information
1 parent 574dfa0 commit 6230dc7
219 files changed
Lines changed: 2434 additions & 1612 deletions
File tree
- apps
- docs/content/docs
- dotcom/client/src
- fairy/actions
- tla/components/TlaEditor
- examples
- e2e/tests
- src
- examples
- add-tool-to-toolbar
- after-create-update-shape
- after-delete-shape
- ag-grid-shape
- api
- bounds-snapping-shape/PlayingCardShape
- create-arrow
- cubic-bezier-shape
- custom-clipping-shape
- custom-config/CardShape
- custom-error-capture
- custom-paste
- custom-relative-snapping
- custom-renderer
- custom-shape
- custom-tool
- drag-and-drop-tray
- drag-and-drop
- easter-egg-styles
- editable-shape
- error-boundary
- exam-marking
- pdf-editor
- external-content-sources
- image-annotator
- interaction-end-callback
- interactive-shape
- layout-bindings
- only-editor
- pdf-editor
- permissions-2
- permissions
- pin-bindings
- popup-shape
- prevent-shape-change
- selection-color-condition
- shape-with-custom-styles
- shape-with-geometry
- shape-with-migrations
- shape-with-tldraw-styles
- size-from-dom
- slideshow
- slides
- speech-bubble/SpeechBubble
- sticker-bindings
- sync-custom-shape
- toSvg-method-example
- tool-with-child-states
- misc
- packages
- editor
- src/lib
- editor
- bindings
- derivations
- managers
- FontManager
- SnapManager
- shapes
- group
- tools/BaseBoxShapeTool
- children
- exports
- utils
- store/src/lib
- sync-core/src/test
- tldraw
- src
- lib
- bindings/arrow
- canvas
- shapes
- arrow
- elbow
- toolStates
- bookmark
- draw/toolStates
- embed
- frame
- geo
- toolStates
- line
- toolStates
- note
- text
- toolStates
- tools
- EraserTool/childStates
- SelectTool
- childStates
- Crop/children
- ui
- components
- Toolbar
- context
- hooks
- utils
- excalidraw
- export
- frames
- tldr
- test
- commands
- tlschema
- src
- bindings
- records
- shapes
- templates
- agent
- client/components/chat-history
- branching-chat/client
- components
- connection
- nodes
- types
- ports
- chat/src/components
- workflow/src
- components
- connection
- execution
- nodes
- types
- ports
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
476 | 476 | | |
477 | 477 | | |
478 | 478 | | |
479 | | - | |
| 479 | + | |
480 | 480 | | |
481 | 481 | | |
482 | | - | |
| 482 | + | |
483 | 483 | | |
484 | | - | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
485 | 497 | | |
486 | 498 | | |
487 | | - | |
488 | | - | |
489 | | - | |
| 499 | + | |
490 | 500 | | |
491 | | - | |
| 501 | + | |
492 | 502 | | |
493 | 503 | | |
494 | 504 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
| 99 | + | |
98 | 100 | | |
99 | | - | |
| 101 | + | |
100 | 102 | | |
101 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
102 | 108 | | |
103 | 109 | | |
104 | | - | |
| 110 | + | |
105 | 111 | | |
106 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
107 | 121 | | |
108 | 122 | | |
109 | 123 | | |
| |||
112 | 126 | | |
113 | 127 | | |
114 | 128 | | |
115 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
116 | 132 | | |
117 | 133 | | |
118 | | - | |
| 134 | + | |
119 | 135 | | |
120 | 136 | | |
121 | 137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
6 | 20 | | |
7 | 21 | | |
8 | 22 | | |
| |||
17 | 31 | | |
18 | 32 | | |
19 | 33 | | |
20 | | - | |
21 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
22 | 45 | | |
23 | 46 | | |
24 | 47 | | |
| |||
30 | 53 | | |
31 | 54 | | |
32 | 55 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
| 56 | + | |
38 | 57 | | |
39 | 58 | | |
40 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
Lines changed: 4 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 2 | + | |
9 | 3 | | |
10 | 4 | | |
11 | 5 | | |
| |||
16 | 10 | | |
17 | 11 | | |
18 | 12 | | |
19 | | - | |
| 13 | + | |
20 | 14 | | |
21 | 15 | | |
22 | 16 | | |
| |||
39 | 33 | | |
40 | 34 | | |
41 | 35 | | |
42 | | - | |
| 36 | + | |
43 | 37 | | |
44 | 38 | | |
45 | 39 | | |
| |||
62 | 56 | | |
63 | 57 | | |
64 | 58 | | |
65 | | - | |
| 59 | + | |
66 | 60 | | |
67 | 61 | | |
68 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
1007 | 1006 | | |
1008 | 1007 | | |
1009 | 1008 | | |
1010 | | - | |
| 1009 | + | |
1011 | 1010 | | |
1012 | 1011 | | |
1013 | 1012 | | |
| |||
1019 | 1018 | | |
1020 | 1019 | | |
1021 | 1020 | | |
1022 | | - | |
| 1021 | + | |
1023 | 1022 | | |
1024 | 1023 | | |
1025 | 1024 | | |
| |||
1034 | 1033 | | |
1035 | 1034 | | |
1036 | 1035 | | |
1037 | | - | |
| 1036 | + | |
1038 | 1037 | | |
1039 | 1038 | | |
1040 | 1039 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
| 256 | + | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
278 | | - | |
| 278 | + | |
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
300 | | - | |
| 300 | + | |
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | | - | |
| 322 | + | |
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | | - | |
| 372 | + | |
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
16 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
17 | 22 | | |
18 | 23 | | |
19 | 24 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
0 commit comments