@tldraw/editor 3.9.0-internal.7f0e15f4f7d9 → 3.10.0-canary.3bf31007c5a7

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 (63) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/README.md +1 -1
  3. package/dist-cjs/index.d.ts +43 -7
  4. package/dist-cjs/index.js +1 -1
  5. package/dist-cjs/index.js.map +2 -2
  6. package/dist-cjs/lib/TldrawEditor.js +2 -3
  7. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  8. package/dist-cjs/lib/components/LiveCollaborators.js +5 -0
  9. package/dist-cjs/lib/components/LiveCollaborators.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultBrush.js.map +2 -2
  11. package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +2 -2
  12. package/dist-cjs/lib/components/default-components/DefaultCursor.js.map +2 -2
  13. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
  14. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
  15. package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
  16. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  17. package/dist-cjs/lib/editor/Editor.js +435 -252
  18. package/dist-cjs/lib/editor/Editor.js.map +3 -3
  19. package/dist-cjs/lib/editor/managers/FontManager.js +25 -26
  20. package/dist-cjs/lib/editor/managers/FontManager.js.map +2 -2
  21. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +7 -2
  22. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  23. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  24. package/dist-cjs/version.js +3 -3
  25. package/dist-cjs/version.js.map +1 -1
  26. package/dist-esm/index.d.mts +43 -7
  27. package/dist-esm/index.mjs +1 -1
  28. package/dist-esm/index.mjs.map +2 -2
  29. package/dist-esm/lib/TldrawEditor.mjs +2 -3
  30. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  31. package/dist-esm/lib/components/LiveCollaborators.mjs +5 -0
  32. package/dist-esm/lib/components/LiveCollaborators.mjs.map +2 -2
  33. package/dist-esm/lib/components/default-components/DefaultBrush.mjs.map +2 -2
  34. package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +2 -2
  35. package/dist-esm/lib/components/default-components/DefaultCursor.mjs.map +2 -2
  36. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
  37. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
  38. package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
  39. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  40. package/dist-esm/lib/editor/Editor.mjs +431 -248
  41. package/dist-esm/lib/editor/Editor.mjs.map +3 -3
  42. package/dist-esm/lib/editor/managers/FontManager.mjs +26 -27
  43. package/dist-esm/lib/editor/managers/FontManager.mjs.map +2 -2
  44. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +7 -2
  45. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  46. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  47. package/dist-esm/version.mjs +3 -3
  48. package/dist-esm/version.mjs.map +1 -1
  49. package/package.json +7 -7
  50. package/src/index.ts +2 -0
  51. package/src/lib/TldrawEditor.tsx +3 -3
  52. package/src/lib/components/LiveCollaborators.tsx +5 -0
  53. package/src/lib/components/default-components/DefaultBrush.tsx +1 -0
  54. package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -0
  55. package/src/lib/components/default-components/DefaultCursor.tsx +1 -0
  56. package/src/lib/components/default-components/DefaultErrorFallback.tsx +5 -3
  57. package/src/lib/components/default-components/DefaultScribble.tsx +1 -0
  58. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +1 -0
  59. package/src/lib/editor/Editor.ts +560 -276
  60. package/src/lib/editor/managers/FontManager.ts +26 -27
  61. package/src/lib/editor/shapes/ShapeUtil.ts +32 -5
  62. package/src/lib/exports/getSvgJsx.tsx +1 -0
  63. package/src/version.ts +3 -3
@@ -1,4 +1,5 @@
1
- import { atom, Atom, EMPTY_ARRAY, transact } from '@tldraw/state'
1
+ import { computed, EMPTY_ARRAY, transact } from '@tldraw/state'
2
+ import { AtomMap } from '@tldraw/store'
2
3
  import { TLShape, TLShapeId } from '@tldraw/tlschema'
3
4
  import {
4
5
  areArraysShallowEqual,
@@ -96,13 +97,18 @@ export class FontManager {
96
97
  { areResultsEqual: areArraysShallowEqual }
97
98
  )
98
99
 
99
- this.shapeFontLoadStateCache = editor.store.createComputedCache(
100
- 'shape font load state',
101
- (shape: TLShape) => {
102
- const states = this.getShapeFontFaces(shape).map((face) => this.getFontState(face))
103
- return states
104
- },
105
- { areResultsEqual: areArraysShallowEqual }
100
+ this.shapeFontLoadStateCache = editor.store.createCache<(FontState | null)[], TLShape>(
101
+ (id: TLShapeId) => {
102
+ const fontFacesComputed = computed('font faces', () => this.getShapeFontFaces(id))
103
+ return computed(
104
+ 'font load state',
105
+ () => {
106
+ const states = fontFacesComputed.get().map((face) => this.getFontState(face))
107
+ return states
108
+ },
109
+ { isEqual: areArraysShallowEqual }
110
+ )
111
+ }
106
112
  )
107
113
  }
108
114
 
@@ -135,40 +141,33 @@ export class FontManager {
135
141
  await Promise.all(promises)
136
142
  }
137
143
 
138
- private readonly fontStates = atom<ReadonlyMap<TLFontFace, Atom<FontState>>>(
139
- 'font states',
140
- new Map()
141
- )
144
+ private readonly fontStates = new AtomMap<TLFontFace, FontState>('font states')
142
145
  private getFontState(font: TLFontFace): FontState | null {
143
- return this.fontStates.get().get(font)?.get() ?? null
146
+ return this.fontStates.get(font) ?? null
144
147
  }
145
148
 
146
149
  ensureFontIsLoaded(font: TLFontFace): Promise<void> {
147
- const state = this.getFontState(font)
148
- if (state) return state.loadingPromise
150
+ const existingState = this.getFontState(font)
151
+ if (existingState) return existingState.loadingPromise
149
152
 
150
153
  const instance = this.findOrCreateFontFace(font)
151
- const stateAtom = atom<FontState>('font state', {
154
+ const state: FontState = {
152
155
  state: 'loading',
153
156
  instance,
154
157
  loadingPromise: instance
155
158
  .load()
156
159
  .then(() => {
157
160
  document.fonts.add(instance)
158
- stateAtom.update((s) => ({ ...s, state: 'ready' }))
161
+ this.fontStates.update(font, (s) => ({ ...s, state: 'ready' }))
159
162
  })
160
163
  .catch((err) => {
161
164
  console.error(err)
162
- stateAtom.update((s) => ({ ...s, state: 'error' }))
165
+ this.fontStates.update(font, (s) => ({ ...s, state: 'error' }))
163
166
  }),
164
- })
165
- this.fontStates.update((map) => {
166
- const newMap = new Map(map)
167
- newMap.set(font, stateAtom)
168
- return newMap
169
- })
167
+ }
170
168
 
171
- return stateAtom.get().loadingPromise
169
+ this.fontStates.set(font, state)
170
+ return state.loadingPromise
172
171
  }
173
172
 
174
173
  private fontsToLoad = new Set<TLFontFace>()
@@ -224,8 +223,7 @@ export class FontManager {
224
223
  ]).join(' ')
225
224
  return compact([
226
225
  `@font-face {`,
227
- ` font-family: ${font.family};`,
228
- ` src: ${src};`,
226
+ ` font-family: "${font.family}";`,
229
227
  font.ascentOverride ? ` ascent-override: ${font.ascentOverride};` : null,
230
228
  font.descentOverride ? ` descent-override: ${font.descentOverride};` : null,
231
229
  font.stretch ? ` font-stretch: ${font.stretch};` : null,
@@ -234,6 +232,7 @@ export class FontManager {
234
232
  font.featureSettings ? ` font-feature-settings: ${font.featureSettings};` : null,
235
233
  font.lineGapOverride ? ` line-gap-override: ${font.lineGapOverride};` : null,
236
234
  font.unicodeRange ? ` unicode-range: ${font.unicodeRange};` : null,
235
+ ` src: ${src};`,
237
236
  `}`,
238
237
  ]).join('\n')
239
238
  }
@@ -38,7 +38,7 @@ export interface TLShapeUtilConstructor<
38
38
  *
39
39
  * @public
40
40
  */
41
- export interface TLShapeUtilCanBindOpts<Shape extends TLUnknownShape = TLShape> {
41
+ export interface TLShapeUtilCanBindOpts<Shape extends TLUnknownShape = TLUnknownShape> {
42
42
  /** The type of shape referenced by the `fromId` of the binding. */
43
43
  fromShapeType: string
44
44
  /** The type of shape referenced by the `toId` of the binding. */
@@ -47,6 +47,27 @@ export interface TLShapeUtilCanBindOpts<Shape extends TLUnknownShape = TLShape>
47
47
  bindingType: string
48
48
  }
49
49
 
50
+ /**
51
+ * Options passed to {@link ShapeUtil.canBeLaidOut}.
52
+ *
53
+ * @public
54
+ */
55
+ export interface TLShapeUtilCanBeLaidOutOpts {
56
+ /** The type of action causing the layout. */
57
+ type?: 'align' | 'distribute' | 'pack' | 'stack' | 'flip' | 'stretch'
58
+ /** The other shapes being laid out */
59
+ shapes?: TLShape[]
60
+ }
61
+
62
+ /** Additional options for the {@link ShapeUtil.getGeometry} method.
63
+ *
64
+ * @public
65
+ */
66
+ export interface TLGeometryOpts {
67
+ /** The context in which the geometry is being requested. */
68
+ context?: string
69
+ }
70
+
50
71
  /** @public */
51
72
  export interface TLShapeUtilCanvasSvgDef {
52
73
  key: string
@@ -130,9 +151,10 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
130
151
  * Get the shape's geometry.
131
152
  *
132
153
  * @param shape - The shape.
154
+ * @param opts - Additional options for the request.
133
155
  * @public
134
156
  */
135
- abstract getGeometry(shape: Shape): Geometry2d
157
+ abstract getGeometry(shape: Shape, opts?: TLGeometryOpts): Geometry2d
136
158
 
137
159
  /**
138
160
  * Get a JSX element for the shape (as an HTML element).
@@ -164,6 +186,7 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
164
186
  /**
165
187
  * Whether the shape can be snapped to by another shape.
166
188
  *
189
+ * @param shape - The shape.
167
190
  * @public
168
191
  */
169
192
  canSnap(_shape: Shape): boolean {
@@ -184,7 +207,7 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
184
207
  *
185
208
  * @public
186
209
  */
187
- canBind(_opts: TLShapeUtilCanBindOpts<Shape>): boolean {
210
+ canBind(_opts: TLShapeUtilCanBindOpts): boolean {
188
211
  return true
189
212
  }
190
213
 
@@ -225,11 +248,15 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
225
248
  }
226
249
 
227
250
  /**
228
- * Whether the shape participates in stacking, aligning, and distributing.
251
+ * Whether the shape can participate in layout functions such as alignment or distribution.
252
+ *
253
+ * @param shape - The shape.
254
+ * @param info - Additional context information: the type of action causing the layout and the
255
+ * @public
229
256
  *
230
257
  * @public
231
258
  */
232
- canBeLaidOut(_shape: Shape): boolean {
259
+ canBeLaidOut(_shape: Shape, _info: TLShapeUtilCanBeLaidOutOpts): boolean {
233
260
  return true
234
261
  }
235
262
 
@@ -206,6 +206,7 @@ function SvgExport({
206
206
  ;(async () => {
207
207
  const shapeDefs: Record<string, { pending: false; element: ReactElement }> = {}
208
208
 
209
+ // Then render everything. The shapes with assets should all hit the cache
209
210
  const unorderedShapeElementPromises = renderingShapes.map(
210
211
  async ({ id, opacity, index, backgroundIndex }) => {
211
212
  // Don't render the frame if we're only exporting a single frame and it's children
package/src/version.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  // This file is automatically generated by internal/scripts/refresh-assets.ts.
2
2
  // Do not edit manually. Or do, I'm a comment, not a cop.
3
3
 
4
- export const version = '3.9.0-internal.7f0e15f4f7d9'
4
+ export const version = '3.10.0-canary.3bf31007c5a7'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2025-02-25T14:10:40.799Z',
8
- patch: '2025-02-25T14:10:40.799Z',
7
+ minor: '2025-03-03T14:30:27.310Z',
8
+ patch: '2025-03-03T14:30:27.310Z',
9
9
  }