tldraw 3.16.0-canary.5dac57cf9465 → 3.16.0-canary.6f3aedaa1c01
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/dist-cjs/index.d.ts +32 -1
- package/dist-cjs/index.js +2 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js +3 -3
- package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js +3 -3
- package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +12 -12
- package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js +2 -2
- package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js +2 -1
- package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js.map +2 -2
- package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js +5 -1
- package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/line/LineShapeUtil.js +5 -1
- package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +4 -4
- package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/ShapeFill.js +5 -5
- package/dist-cjs/lib/shapes/shared/ShapeFill.js.map +2 -2
- package/dist-cjs/lib/shapes/text/TextShapeUtil.js +2 -2
- package/dist-cjs/lib/shapes/text/TextShapeUtil.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
- package/dist-cjs/lib/ui/components/MobileStylePanel.js +1 -1
- package/dist-cjs/lib/ui/components/MobileStylePanel.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js +1 -1
- package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +30 -13
- package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js +152 -1
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js.map +2 -2
- package/dist-cjs/lib/ui/context/events.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useTools.js +76 -9
- package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
- package/dist-cjs/lib/ui/version.js +3 -3
- package/dist-cjs/lib/ui/version.js.map +1 -1
- package/dist-esm/index.d.mts +32 -1
- package/dist-esm/index.mjs +3 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +4 -3
- package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs +4 -3
- package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs +13 -12
- package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs +3 -2
- package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs +2 -1
- package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs.map +2 -2
- package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs +6 -1
- package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +6 -1
- package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +5 -4
- package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/ShapeFill.mjs +6 -5
- package/dist-esm/lib/shapes/shared/ShapeFill.mjs.map +2 -2
- package/dist-esm/lib/shapes/text/TextShapeUtil.mjs +3 -2
- package/dist-esm/lib/shapes/text/TextShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
- package/dist-esm/lib/ui/components/MobileStylePanel.mjs +2 -1
- package/dist-esm/lib/ui/components/MobileStylePanel.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs +2 -1
- package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs +31 -14
- package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs +160 -3
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs.map +2 -2
- package/dist-esm/lib/ui/context/events.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useTools.mjs +83 -10
- package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
- package/dist-esm/lib/ui/version.mjs +3 -3
- package/dist-esm/lib/ui/version.mjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +2 -0
- package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +4 -3
- package/src/lib/shapes/draw/DrawShapeUtil.tsx +4 -3
- package/src/lib/shapes/frame/FrameShapeUtil.tsx +13 -14
- package/src/lib/shapes/geo/GeoShapeUtil.tsx +3 -2
- package/src/lib/shapes/geo/components/GeoShapeBody.tsx +2 -2
- package/src/lib/shapes/highlight/HighlightShapeUtil.tsx +7 -1
- package/src/lib/shapes/line/LineShapeUtil.tsx +6 -1
- package/src/lib/shapes/note/NoteShapeUtil.tsx +9 -4
- package/src/lib/shapes/shared/ShapeFill.tsx +6 -5
- package/src/lib/shapes/text/TextShapeUtil.tsx +3 -2
- package/src/lib/tools/SelectTool/childStates/Translating.ts +0 -1
- package/src/lib/ui/components/MobileStylePanel.tsx +5 -3
- package/src/lib/ui/components/primitives/TldrawUiButtonPicker.tsx +3 -2
- package/src/lib/ui/components/primitives/TldrawUiTooltip.tsx +35 -16
- package/src/lib/ui/components/primitives/menus/TldrawUiMenuItem.tsx +218 -2
- package/src/lib/ui/context/events.tsx +1 -0
- package/src/lib/ui/hooks/useTools.tsx +118 -10
- package/src/lib/ui/version.ts +3 -3
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
assertExists,
|
|
3
|
+
createShapeId,
|
|
4
|
+
Editor,
|
|
5
|
+
GeoShapeGeoStyle,
|
|
6
|
+
TLPointerEventInfo,
|
|
7
|
+
TLShapeId,
|
|
8
|
+
toRichText,
|
|
9
|
+
useMaybeEditor,
|
|
10
|
+
} from '@tldraw/editor'
|
|
2
11
|
import * as React from 'react'
|
|
3
12
|
import { EmbedDialog } from '../components/EmbedDialog'
|
|
4
13
|
import { TLUiIconJsx } from '../components/primitives/TldrawUiIcon'
|
|
@@ -19,6 +28,7 @@ export interface TLUiToolItem<
|
|
|
19
28
|
shortcutsLabel?: TranslationKey
|
|
20
29
|
icon: IconType | TLUiIconJsx
|
|
21
30
|
onSelect(source: TLUiEventSource): void
|
|
31
|
+
onDragStart?(source: TLUiEventSource, info: TLPointerEventInfo): void
|
|
22
32
|
/**
|
|
23
33
|
* The keyboard shortcut for this tool. This is a string that can be a single key,
|
|
24
34
|
* or a combination of keys.
|
|
@@ -126,21 +136,27 @@ export function ToolsProvider({ overrides, children }: TLUiToolsProviderProps) {
|
|
|
126
136
|
onToolSelect(source, this)
|
|
127
137
|
},
|
|
128
138
|
},
|
|
129
|
-
...[...GeoShapeGeoStyle.values].map((
|
|
130
|
-
id,
|
|
131
|
-
label: `tool.${
|
|
139
|
+
...[...GeoShapeGeoStyle.values].map((geo) => ({
|
|
140
|
+
id: geo,
|
|
141
|
+
label: `tool.${geo}` as TLUiTranslationKey,
|
|
132
142
|
meta: {
|
|
133
|
-
geo
|
|
143
|
+
geo,
|
|
134
144
|
},
|
|
135
|
-
kbd:
|
|
136
|
-
icon: ('geo-' +
|
|
145
|
+
kbd: geo === 'rectangle' ? 'r' : geo === 'ellipse' ? 'o' : undefined,
|
|
146
|
+
icon: ('geo-' + geo) as TLUiIconType,
|
|
137
147
|
onSelect(source: TLUiEventSource) {
|
|
138
148
|
editor.run(() => {
|
|
139
|
-
editor.setStyleForNextShapes(GeoShapeGeoStyle,
|
|
149
|
+
editor.setStyleForNextShapes(GeoShapeGeoStyle, geo)
|
|
140
150
|
editor.setCurrentTool('geo')
|
|
141
|
-
onToolSelect(source, this, `geo-${
|
|
151
|
+
onToolSelect(source, this, `geo-${geo}`)
|
|
142
152
|
})
|
|
143
153
|
},
|
|
154
|
+
onDragStart(source: TLUiEventSource, info: TLPointerEventInfo) {
|
|
155
|
+
onDragFromToolbarToCreateShape(editor, info, {
|
|
156
|
+
createShape: (id) => editor.createShape({ id, type: 'geo', props: { geo } }),
|
|
157
|
+
})
|
|
158
|
+
trackEvent('drag-tool', { source, id: 'geo' })
|
|
159
|
+
},
|
|
144
160
|
})),
|
|
145
161
|
{
|
|
146
162
|
id: 'arrow',
|
|
@@ -151,6 +167,17 @@ export function ToolsProvider({ overrides, children }: TLUiToolsProviderProps) {
|
|
|
151
167
|
editor.setCurrentTool('arrow')
|
|
152
168
|
onToolSelect(source, this)
|
|
153
169
|
},
|
|
170
|
+
onDragStart(source: TLUiEventSource, info: TLPointerEventInfo) {
|
|
171
|
+
onDragFromToolbarToCreateShape(editor, info, {
|
|
172
|
+
createShape: (id) =>
|
|
173
|
+
editor.createShape({
|
|
174
|
+
id,
|
|
175
|
+
type: 'arrow',
|
|
176
|
+
props: { start: { x: 0, y: 0 }, end: { x: 200, y: 0 } },
|
|
177
|
+
}),
|
|
178
|
+
})
|
|
179
|
+
trackEvent('drag-tool', { source, id: 'arrow' })
|
|
180
|
+
},
|
|
154
181
|
},
|
|
155
182
|
{
|
|
156
183
|
id: 'line',
|
|
@@ -171,6 +198,12 @@ export function ToolsProvider({ overrides, children }: TLUiToolsProviderProps) {
|
|
|
171
198
|
editor.setCurrentTool('frame')
|
|
172
199
|
onToolSelect(source, this)
|
|
173
200
|
},
|
|
201
|
+
onDragStart(source, info) {
|
|
202
|
+
onDragFromToolbarToCreateShape(editor, info, {
|
|
203
|
+
createShape: (id) => editor.createShape({ id, type: 'frame' }),
|
|
204
|
+
})
|
|
205
|
+
trackEvent('drag-tool', { source, id: 'frame' })
|
|
206
|
+
},
|
|
174
207
|
},
|
|
175
208
|
{
|
|
176
209
|
id: 'text',
|
|
@@ -181,6 +214,17 @@ export function ToolsProvider({ overrides, children }: TLUiToolsProviderProps) {
|
|
|
181
214
|
editor.setCurrentTool('text')
|
|
182
215
|
onToolSelect(source, this)
|
|
183
216
|
},
|
|
217
|
+
onDragStart(source, info) {
|
|
218
|
+
onDragFromToolbarToCreateShape(editor, info, {
|
|
219
|
+
createShape: (id) =>
|
|
220
|
+
editor.createShape({ id, type: 'text', props: { richText: toRichText('Text') } }),
|
|
221
|
+
onDragEnd: (id) => {
|
|
222
|
+
editor.emit('select-all-text', { shapeId: id })
|
|
223
|
+
editor.setEditingShape(id)
|
|
224
|
+
},
|
|
225
|
+
})
|
|
226
|
+
trackEvent('drag-tool', { source, id: 'text' })
|
|
227
|
+
},
|
|
184
228
|
},
|
|
185
229
|
{
|
|
186
230
|
id: 'asset',
|
|
@@ -201,6 +245,16 @@ export function ToolsProvider({ overrides, children }: TLUiToolsProviderProps) {
|
|
|
201
245
|
editor.setCurrentTool('note')
|
|
202
246
|
onToolSelect(source, this)
|
|
203
247
|
},
|
|
248
|
+
onDragStart(source, info) {
|
|
249
|
+
onDragFromToolbarToCreateShape(editor, info, {
|
|
250
|
+
createShape: (id) => editor.createShape({ id, type: 'note' }),
|
|
251
|
+
onDragEnd: (id) => {
|
|
252
|
+
editor.emit('select-all-text', { shapeId: id })
|
|
253
|
+
editor.setEditingShape(id)
|
|
254
|
+
},
|
|
255
|
+
})
|
|
256
|
+
trackEvent('drag-tool', { source, id: 'note' })
|
|
257
|
+
},
|
|
204
258
|
},
|
|
205
259
|
{
|
|
206
260
|
id: 'laser',
|
|
@@ -244,7 +298,7 @@ export function ToolsProvider({ overrides, children }: TLUiToolsProviderProps) {
|
|
|
244
298
|
}
|
|
245
299
|
|
|
246
300
|
return tools
|
|
247
|
-
}, [overrides, editor, helpers, onToolSelect])
|
|
301
|
+
}, [overrides, editor, helpers, onToolSelect, trackEvent])
|
|
248
302
|
|
|
249
303
|
return <ToolsContext.Provider value={tools}>{children}</ToolsContext.Provider>
|
|
250
304
|
}
|
|
@@ -259,3 +313,57 @@ export function useTools() {
|
|
|
259
313
|
|
|
260
314
|
return ctx
|
|
261
315
|
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Options for {@link onDragFromToolbarToCreateShape}.
|
|
319
|
+
* @public
|
|
320
|
+
*/
|
|
321
|
+
export interface OnDragFromToolbarToCreateShapesOpts {
|
|
322
|
+
/**
|
|
323
|
+
* Create the shape being dragged. You don't need to worry about positioning it, as it'll be
|
|
324
|
+
* immediately updated with the correct position.
|
|
325
|
+
*/
|
|
326
|
+
createShape(id: TLShapeId): void
|
|
327
|
+
/**
|
|
328
|
+
* Called once the drag interaction has finished.
|
|
329
|
+
*/
|
|
330
|
+
onDragEnd?(id: TLShapeId): void
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* A helper method to use in {@link TLUiToolItem#onDragStart} to create a shape by dragging it from
|
|
335
|
+
* the toolbar.
|
|
336
|
+
* @public
|
|
337
|
+
*/
|
|
338
|
+
export function onDragFromToolbarToCreateShape(
|
|
339
|
+
editor: Editor,
|
|
340
|
+
info: TLPointerEventInfo,
|
|
341
|
+
opts: OnDragFromToolbarToCreateShapesOpts
|
|
342
|
+
) {
|
|
343
|
+
const { x, y } = editor.inputs.currentPagePoint
|
|
344
|
+
|
|
345
|
+
const stoppingPoint = editor.markHistoryStoppingPoint('drag shape tool')
|
|
346
|
+
editor.setCurrentTool('select.translating')
|
|
347
|
+
|
|
348
|
+
const id = createShapeId()
|
|
349
|
+
opts.createShape(id)
|
|
350
|
+
const shape = assertExists(editor.getShape(id), 'Shape not found')
|
|
351
|
+
|
|
352
|
+
const { w, h } = editor.getShapePageBounds(id)!
|
|
353
|
+
editor.updateShape({ id, type: shape.type, x: x - w / 2, y: y - h / 2 })
|
|
354
|
+
editor.select(id)
|
|
355
|
+
|
|
356
|
+
editor.setCurrentTool('select.translating', {
|
|
357
|
+
...info,
|
|
358
|
+
target: 'shape',
|
|
359
|
+
shape: editor.getShape(id),
|
|
360
|
+
isCreating: true,
|
|
361
|
+
creatingMarkId: stoppingPoint,
|
|
362
|
+
onCreate() {
|
|
363
|
+
editor.setCurrentTool('select.idle')
|
|
364
|
+
editor.select(id)
|
|
365
|
+
opts.onDragEnd?.(id)
|
|
366
|
+
},
|
|
367
|
+
})
|
|
368
|
+
editor.getCurrentTool().setCurrentToolIdMask(shape.type)
|
|
369
|
+
}
|
package/src/lib/ui/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.16.0-canary.
|
|
4
|
+
export const version = '3.16.0-canary.6f3aedaa1c01'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2024-09-13T14:36:29.063Z',
|
|
7
|
-
minor: '2025-08-
|
|
8
|
-
patch: '2025-08-
|
|
7
|
+
minor: '2025-08-11T09:05:51.468Z',
|
|
8
|
+
patch: '2025-08-11T09:05:51.468Z',
|
|
9
9
|
}
|