@tldraw/editor 3.9.0-internal.7f0e15f4f7d9 → 3.10.0-canary.075415a2bbc8
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/CHANGELOG.md +90 -0
- package/README.md +2 -2
- package/dist-cjs/index.d.ts +54 -9
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +2 -3
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/LiveCollaborators.js +5 -0
- package/dist-cjs/lib/components/LiveCollaborators.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultBrush.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCursor.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +430 -248
- package/dist-cjs/lib/editor/Editor.js.map +3 -3
- package/dist-cjs/lib/editor/managers/FontManager.js +25 -26
- package/dist-cjs/lib/editor/managers/FontManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +7 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/exports/StyleEmbedder.js +1 -1
- package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/hooks/usePeerIds.js.map +1 -1
- package/dist-cjs/lib/hooks/usePresence.js.map +1 -1
- package/dist-cjs/lib/license/Watermark.js +1 -1
- package/dist-cjs/lib/license/Watermark.js.map +1 -1
- package/dist-cjs/lib/utils/browserCanvasMaxSize.js +5 -0
- package/dist-cjs/lib/utils/browserCanvasMaxSize.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +54 -9
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +2 -3
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/LiveCollaborators.mjs +5 -0
- package/dist-esm/lib/components/LiveCollaborators.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultBrush.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCursor.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +431 -249
- package/dist-esm/lib/editor/Editor.mjs.map +3 -3
- package/dist-esm/lib/editor/managers/FontManager.mjs +26 -27
- package/dist-esm/lib/editor/managers/FontManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +7 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/exports/StyleEmbedder.mjs +1 -1
- package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePeerIds.mjs.map +1 -1
- package/dist-esm/lib/hooks/usePresence.mjs.map +1 -1
- package/dist-esm/lib/license/Watermark.mjs +1 -1
- package/dist-esm/lib/license/Watermark.mjs.map +1 -1
- package/dist-esm/lib/utils/browserCanvasMaxSize.mjs +5 -0
- package/dist-esm/lib/utils/browserCanvasMaxSize.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +4 -0
- package/package.json +7 -7
- package/src/index.ts +2 -0
- package/src/lib/TldrawEditor.tsx +3 -3
- package/src/lib/components/LiveCollaborators.tsx +5 -0
- package/src/lib/components/default-components/DefaultBrush.tsx +1 -0
- package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -0
- package/src/lib/components/default-components/DefaultCursor.tsx +1 -0
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +5 -3
- package/src/lib/components/default-components/DefaultScribble.tsx +1 -0
- package/src/lib/components/default-components/DefaultShapeIndicator.tsx +1 -0
- package/src/lib/editor/Editor.ts +560 -277
- package/src/lib/editor/managers/FontManager.ts +26 -27
- package/src/lib/editor/shapes/ShapeUtil.ts +32 -5
- package/src/lib/exports/StyleEmbedder.ts +1 -1
- package/src/lib/exports/getSvgJsx.tsx +1 -0
- package/src/lib/hooks/usePeerIds.ts +1 -1
- package/src/lib/hooks/usePresence.ts +2 -2
- package/src/lib/license/Watermark.tsx +1 -1
- package/src/lib/utils/browserCanvasMaxSize.ts +5 -3
- package/src/version.ts +3 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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 =
|
|
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(
|
|
146
|
+
return this.fontStates.get(font) ?? null
|
|
144
147
|
}
|
|
145
148
|
|
|
146
149
|
ensureFontIsLoaded(font: TLFontFace): Promise<void> {
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
150
|
+
const existingState = this.getFontState(font)
|
|
151
|
+
if (existingState) return existingState.loadingPromise
|
|
149
152
|
|
|
150
153
|
const instance = this.findOrCreateFontFace(font)
|
|
151
|
-
const
|
|
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
|
-
|
|
161
|
+
this.fontStates.update(font, (s) => ({ ...s, state: 'ready' }))
|
|
159
162
|
})
|
|
160
163
|
.catch((err) => {
|
|
161
164
|
console.error(err)
|
|
162
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
|
@@ -242,7 +242,7 @@ function styleFromComputedStyle(
|
|
|
242
242
|
{ defaultStyles, parentStyles }: ReadStyleOpts
|
|
243
243
|
) {
|
|
244
244
|
const styles: Record<string, string> = {}
|
|
245
|
-
for (const
|
|
245
|
+
for (const property in style) {
|
|
246
246
|
if (!shouldIncludeCssProperty(property)) continue
|
|
247
247
|
|
|
248
248
|
const value = style.getPropertyValue(property)
|
|
@@ -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
|
|
@@ -4,8 +4,8 @@ import { useEditor } from './useEditor'
|
|
|
4
4
|
|
|
5
5
|
// TODO: maybe move this to a computed property on the App class?
|
|
6
6
|
/**
|
|
7
|
-
* @returns The
|
|
8
|
-
* @
|
|
7
|
+
* @returns The latest presence of the user matching userId
|
|
8
|
+
* @public
|
|
9
9
|
*/
|
|
10
10
|
export function usePresence(userId: string): TLInstancePresence | null {
|
|
11
11
|
const editor = useEditor()
|
|
@@ -46,7 +46,7 @@ const WatermarkInner = memo(function WatermarkInner({ src }: { src: string }) {
|
|
|
46
46
|
usePassThroughWheelEvents(ref)
|
|
47
47
|
|
|
48
48
|
const maskCss = `url('${src}') center 100% / 100% no-repeat`
|
|
49
|
-
const url = 'https://tldraw.dev'
|
|
49
|
+
const url = 'https://tldraw.dev/?utm_source=dotcom&utm_medium=organic&utm_campaign=watermark'
|
|
50
50
|
|
|
51
51
|
return (
|
|
52
52
|
<div
|
|
@@ -19,9 +19,11 @@ function getBrowserCanvasMaxSize(): CanvasMaxSize {
|
|
|
19
19
|
return maxCanvasSizes
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
/*!
|
|
23
|
+
* Extracted from https://github.com/jhildenbiddle/canvas-size
|
|
24
|
+
* MIT License: https://github.com/jhildenbiddle/canvas-size/blob/master/LICENSE
|
|
25
|
+
* Copyright (c) John Hildenbiddle
|
|
26
|
+
*/
|
|
25
27
|
|
|
26
28
|
const MAX_SAFE_CANVAS_DIMENSION = 8192
|
|
27
29
|
const MAX_SAFE_CANVAS_AREA = 4096 * 4096
|
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.
|
|
4
|
+
export const version = '3.10.0-canary.075415a2bbc8'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2024-09-13T14:36:29.063Z',
|
|
7
|
-
minor: '2025-
|
|
8
|
-
patch: '2025-
|
|
7
|
+
minor: '2025-03-10T22:20:43.042Z',
|
|
8
|
+
patch: '2025-03-10T22:20:43.042Z',
|
|
9
9
|
}
|