@tldraw/editor 3.12.0-canary.72ffd91308d1 → 3.12.0-canary.956117bf4f16
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 +3 -0
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/components/Shape.js +8 -12
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +7 -12
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +1 -1
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
- package/dist-cjs/lib/editor/tools/StateNode.js +4 -1
- package/dist-cjs/lib/editor/tools/StateNode.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +12 -7
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +3 -3
- package/dist-cjs/lib/hooks/useGestureEvents.js +12 -6
- package/dist-cjs/lib/hooks/useGestureEvents.js.map +2 -2
- package/dist-cjs/lib/utils/debug-flags.js +2 -1
- package/dist-cjs/lib/utils/debug-flags.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 +3 -0
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/components/Shape.mjs +9 -13
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +7 -12
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +1 -1
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/StateNode.mjs +4 -1
- package/dist-esm/lib/editor/tools/StateNode.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +12 -7
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +3 -3
- package/dist-esm/lib/hooks/useGestureEvents.mjs +12 -6
- package/dist-esm/lib/hooks/useGestureEvents.mjs.map +2 -2
- package/dist-esm/lib/utils/debug-flags.mjs +2 -1
- package/dist-esm/lib/utils/debug-flags.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +7 -7
- package/src/lib/components/Shape.tsx +13 -17
- package/src/lib/editor/Editor.ts +7 -13
- package/src/lib/editor/derivations/notVisibleShapes.ts +1 -1
- package/src/lib/editor/tools/StateNode.ts +6 -1
- package/src/lib/hooks/useCanvasEvents.ts +14 -7
- package/src/lib/hooks/useGestureEvents.ts +12 -6
- package/src/lib/utils/debug-flags.ts +1 -0
- package/src/version.ts +3 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useValue } from '@tldraw/state-react'
|
|
1
2
|
import React, { useMemo } from 'react'
|
|
2
3
|
import { RIGHT_MOUSE_BUTTON } from '../constants'
|
|
3
4
|
import {
|
|
@@ -11,6 +12,7 @@ import { useEditor } from './useEditor'
|
|
|
11
12
|
|
|
12
13
|
export function useCanvasEvents() {
|
|
13
14
|
const editor = useEditor()
|
|
15
|
+
const currentTool = useValue('current tool', () => editor.getCurrentTool(), [editor])
|
|
14
16
|
|
|
15
17
|
const events = useMemo(
|
|
16
18
|
function canvasEvents() {
|
|
@@ -49,12 +51,17 @@ export function useCanvasEvents() {
|
|
|
49
51
|
lastX = e.clientX
|
|
50
52
|
lastY = e.clientY
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
// For tools that benefit from a higher fidelity of events,
|
|
55
|
+
// we dispatch the coalesced events.
|
|
56
|
+
const events = currentTool.useCoalescedEvents ? e.nativeEvent.getCoalescedEvents() : [e]
|
|
57
|
+
for (const singleEvent of events) {
|
|
58
|
+
editor.dispatch({
|
|
59
|
+
type: 'pointer',
|
|
60
|
+
target: 'canvas',
|
|
61
|
+
name: 'pointer_move',
|
|
62
|
+
...getPointerInfo(singleEvent),
|
|
63
|
+
})
|
|
64
|
+
}
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
function onPointerUp(e: React.PointerEvent) {
|
|
@@ -159,7 +166,7 @@ export function useCanvasEvents() {
|
|
|
159
166
|
onClick,
|
|
160
167
|
}
|
|
161
168
|
},
|
|
162
|
-
[editor]
|
|
169
|
+
[editor, currentTool]
|
|
163
170
|
)
|
|
164
171
|
|
|
165
172
|
return events
|
|
@@ -135,7 +135,6 @@ export function useGestureEvents(ref: React.RefObject<HTMLDivElement>) {
|
|
|
135
135
|
|
|
136
136
|
let initDistanceBetweenFingers = 1 // the distance between the two fingers when the pinch starts
|
|
137
137
|
let initZoom = 1 // the browser's zoom level when the pinch starts
|
|
138
|
-
let currZoom = 1 // the current zoom level according to the pinch gesture recognizer
|
|
139
138
|
let currDistanceBetweenFingers = 0
|
|
140
139
|
const initPointBetweenFingers = new Vec()
|
|
141
140
|
const prevPointBetweenFingers = new Vec()
|
|
@@ -239,7 +238,7 @@ export function useGestureEvents(ref: React.RefObject<HTMLDivElement>) {
|
|
|
239
238
|
|
|
240
239
|
switch (pinchState) {
|
|
241
240
|
case 'zooming': {
|
|
242
|
-
currZoom = offset[0]
|
|
241
|
+
const currZoom = offset[0] ** editor.getCameraOptions().zoomSpeed
|
|
243
242
|
|
|
244
243
|
editor.dispatch({
|
|
245
244
|
type: 'pinch',
|
|
@@ -278,7 +277,7 @@ export function useGestureEvents(ref: React.RefObject<HTMLDivElement>) {
|
|
|
278
277
|
if (event instanceof WheelEvent) return
|
|
279
278
|
if (!(event.target === elm || elm?.contains(event.target as Node))) return
|
|
280
279
|
|
|
281
|
-
const scale = offset[0]
|
|
280
|
+
const scale = offset[0] ** editor.getCameraOptions().zoomSpeed
|
|
282
281
|
|
|
283
282
|
pinchState = 'not sure'
|
|
284
283
|
|
|
@@ -309,14 +308,21 @@ export function useGestureEvents(ref: React.RefObject<HTMLDivElement>) {
|
|
|
309
308
|
target: ref,
|
|
310
309
|
eventOptions: { passive: false },
|
|
311
310
|
pinch: {
|
|
312
|
-
from: () =>
|
|
311
|
+
from: () => {
|
|
312
|
+
const { zoomSpeed } = editor.getCameraOptions()
|
|
313
|
+
const level = editor.getZoomLevel() ** (1 / zoomSpeed)
|
|
314
|
+
return [level, 0]
|
|
315
|
+
}, // Return the camera z to use when pinch starts
|
|
313
316
|
scaleBounds: () => {
|
|
314
317
|
const baseZoom = editor.getBaseZoom()
|
|
315
|
-
const zoomSteps = editor.getCameraOptions()
|
|
318
|
+
const { zoomSteps, zoomSpeed } = editor.getCameraOptions()
|
|
316
319
|
const zoomMin = zoomSteps[0] * baseZoom
|
|
317
320
|
const zoomMax = zoomSteps[zoomSteps.length - 1] * baseZoom
|
|
318
321
|
|
|
319
|
-
return {
|
|
322
|
+
return {
|
|
323
|
+
max: zoomMax ** (1 / zoomSpeed),
|
|
324
|
+
min: zoomMin ** (1 / zoomSpeed),
|
|
325
|
+
}
|
|
320
326
|
},
|
|
321
327
|
},
|
|
322
328
|
})
|
|
@@ -53,6 +53,7 @@ export const debugFlags = {
|
|
|
53
53
|
debugGeometry: createDebugValue('debugGeometry', { defaults: { all: false } }),
|
|
54
54
|
hideShapes: createDebugValue('hideShapes', { defaults: { all: false } }),
|
|
55
55
|
editOnType: createDebugValue('editOnType', { defaults: { all: false } }),
|
|
56
|
+
a11y: createDebugValue('a11y', { defaults: { all: false } }),
|
|
56
57
|
} as const
|
|
57
58
|
|
|
58
59
|
declare global {
|
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.12.0-canary.
|
|
4
|
+
export const version = '3.12.0-canary.956117bf4f16'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2024-09-13T14:36:29.063Z',
|
|
7
|
-
minor: '2025-
|
|
8
|
-
patch: '2025-
|
|
7
|
+
minor: '2025-04-01T13:24:54.698Z',
|
|
8
|
+
patch: '2025-04-01T13:24:54.698Z',
|
|
9
9
|
}
|