Commit 839e118
authored
feat(editor): add shape attribution, TLUserStore, and extensible user records (tldraw#8147)
In order to let developers track who created and last edited shapes —
and to display that information in the UI — this PR introduces a shape
attribution system built on a reactive `TLUserStore` provider interface,
note-specific "first edited by" labeling, and extensible user records
via `createTLSchema`.
### What's included
**`TLUserStore` interface** (`@tldraw/tlschema`)
A new optional `users` prop on the editor (and `<Tldraw />`) that
connects tldraw to your auth system. Both methods return reactive
`Signal`s so the editor automatically tracks changes to user data:
- `getCurrentUser()` — returns a `Signal<TLUser | null>` for the active
user (used for both presence broadcasting and shape attribution)
- `resolve(userId)` — returns a `Signal<TLUser | null>` to resolve any
user ID to display info (for rendering attribution labels)
When no provider is given, a default implementation falls back to
`UserPreferences` + the collaborator presence list.
**Unified `TLUser` record type** (`@tldraw/tlschema`)
Collapsed the previous `TLUser` + `TLUserInfo` types into a single
`TLUser` store record (following the `TLAsset` pattern). User records
are document-scoped and persist alongside shapes, assets, and pages —
surviving across boards, clipboard paste, and `.tldr` files.
**Extensible user metadata via `createTLSchema`**
SDK users can now extend user records with custom validated metadata:
```ts
const schema = createTLSchema({
user: {
meta: {
isAdmin: T.boolean,
department: T.string,
},
},
})
```
Custom meta fields are validated when present but treated as optional,
so existing user records remain valid. The new
`createUserRecordType(config?)` function builds the record type with
extended validators.
**Note shape "first edited by" label**
`NoteShapeUtil` now tracks `textFirstEditedBy` in its props and renders
a small attribution label (first name) in the bottom-right corner of the
note. The label resolves the display name through the user store and
shows a tooltip with the full name. This tracks who first added text to
the note — subsequent typo fixes by others don't change the attribution.
Includes a note shape migration (`AddFirstEditedBy`).
<img width="757" height="414" alt="Screenshot 2026-03-04 at 11 20 58"
src="https://github.com/user-attachments/assets/190ea36d-873e-44d7-aa3c-8fefebc7db56"
/>
**New editor methods**
- `editor.getAttributionUser(userId)` — resolves a user record by ID,
asking the `TLUserStore` first (the app's source of truth), falling back
to the `user:` record in the store
- `editor.getAttributionUserId()` — returns the current user's ID for
attribution purposes
- `editor.getAttributionDisplayName(userId)` — resolves a display name
for a user ID, with the same lookup order
**New "Users" example category with four examples**
- **Attribution** — demonstrates wiring up `TLUserStore` with a mock
user switcher and an attribution inspector panel
- **Attribution timeline** — shows a history scrubber that steps through
undo history and displays per-shape attribution metadata
- **Custom user metadata** — shows how to extend `TLUser` records with
custom meta fields (isAdmin, department)
- **Multiplayer sync with custom user data** — integrates custom user
data into tldraw sync
https://github.com/user-attachments/assets/bd476596-67ca-483b-8d1d-bec3f82e35d5
https://github.com/user-attachments/assets/c31f8db6-c7ae-4e21-b0d5-48e079eb5767
fixes tldraw#6115
**Unit tests**
New `attribution.test.ts` covering attribution user stamping, custom
user stores, note `textFirstEditedBy` tracking, and display name
resolution.
### Change type
- [x] `feature`
### Test plan
1. Open the Attribution example — switch between users and create/edit
shapes; verify attribution labels update in the inspector panel
2. Open the Attribution Timeline example — draw shapes, use the scrubber
to step through history, verify per-shape metadata display
3. Open the Custom User Metadata example — switch between users and
verify custom meta (department, admin badge) displays
4. Create note shapes — type text, verify the first name appears in the
bottom-right corner; hover for full name tooltip
5. Copy a note with attribution to a different board — verify the
attribution label persists
- [x] Unit tests
### API changes
- Added `TLUserStore` interface (with reactive `Signal`-based methods)
- Added `TLUser` record type (unified from previous `TLUser` +
`TLUserInfo`)
- Added `UserRecordType`, `createUserId`, `isUserId`, `userIdValidator`
- Added `createUserRecordType(config?)` for extensible user schemas
- Added `UserSchemaInfo` interface
- Added `user` parameter to `createTLSchema()`
- Added `textFirstEditedBy` prop to `TLNoteShapeProps`
- Added `Editor.getAttributionUser()`
- Added `Editor.getAttributionUserId()`
- Added `Editor.getAttributionDisplayName()`
- Removed `TLUserInfo` type (collapsed into `TLUser`)
### Release notes
- Add shape attribution system with `TLUserStore` for connecting tldraw
to your auth system.
- `TLUserStore` methods are reactive (`Signal`-based) so the editor
automatically tracks user data changes.
- Add extensible user records: pass custom meta validators to
`createTLSchema({ user: { meta: ... } })`.
- Add `createUserRecordType()` for building user record types with
custom validation.
- Note shapes now display a small "first edited by" label in the corner.
- New "Users" example category with attribution, attribution timeline,
custom user metadata, and sync examples.1 parent 22eccd8 commit 839e118
59 files changed
Lines changed: 2507 additions & 402 deletions
File tree
- apps
- docs/content/sdk-features
- dotcom/client/src
- pages
- tla
- app
- components
- TlaEditor
- hooks
- utils
- examples/src
- examples
- collaboration/sync-custom-user
- users
- attribution-timeline
- attribution
- custom-user
- sync-custom-user
- mcp-app/src
- packages
- editor
- src
- lib
- config
- editor
- managers/UserPreferencesManager
- shapes
- types
- sync-core/src/test
- sync
- src
- tldraw
- src
- lib
- shapes/note
- utils
- excalidraw
- __snapshots__
- tldr
- __snapshots__
- test
- tlschema
- src
- records
- shapes
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 | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
132 | | - | |
| 133 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
129 | 137 | | |
130 | 138 | | |
131 | 139 | | |
132 | 140 | | |
133 | | - | |
| 141 | + | |
134 | 142 | | |
135 | 143 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
151 | 148 | | |
152 | 149 | | |
153 | | - | |
| 150 | + | |
154 | 151 | | |
155 | | - | |
| 152 | + | |
156 | 153 | | |
157 | 154 | | |
158 | 155 | | |
159 | | - | |
160 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
161 | 167 | | |
162 | 168 | | |
163 | 169 | | |
| |||
167 | 173 | | |
168 | 174 | | |
169 | 175 | | |
170 | | - | |
171 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
172 | 195 | | |
173 | 196 | | |
174 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | | - | |
| 327 | + | |
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
15 | 14 | | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
59 | 60 | | |
60 | | - | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
491 | 491 | | |
492 | 492 | | |
493 | 493 | | |
494 | | - | |
| 494 | + | |
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
| |||
Lines changed: 23 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
39 | | - | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| |||
170 | 174 | | |
171 | 175 | | |
172 | 176 | | |
173 | | - | |
| 177 | + | |
174 | 178 | | |
175 | 179 | | |
176 | 180 | | |
| |||
179 | 183 | | |
180 | 184 | | |
181 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
182 | 202 | | |
183 | 203 | | |
184 | 204 | | |
| |||
188 | 208 | | |
189 | 209 | | |
190 | 210 | | |
191 | | - | |
| 211 | + | |
192 | 212 | | |
193 | 213 | | |
194 | 214 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
79 | 84 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
0 commit comments