@tldraw/editor 4.3.0-canary.ef37ae623ce8 → 4.3.0-canary.ef709265bb13
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 +54 -2
- package/dist-cjs/index.js +2 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +3 -3
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +43 -4
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/DashedOutlineBox.js +1 -1
- package/dist-cjs/lib/editor/shapes/group/DashedOutlineBox.js.map +2 -2
- package/dist-cjs/lib/globals/environment.js +45 -9
- package/dist-cjs/lib/globals/environment.js.map +2 -2
- package/dist-cjs/lib/hooks/useCoarsePointer.js +14 -29
- package/dist-cjs/lib/hooks/useCoarsePointer.js.map +2 -2
- package/dist-cjs/lib/hooks/useZoomCss.js +4 -8
- package/dist-cjs/lib/hooks/useZoomCss.js.map +2 -2
- package/dist-cjs/lib/options.js +3 -1
- package/dist-cjs/lib/options.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 -2
- package/dist-esm/index.mjs +3 -2
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +3 -3
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +43 -4
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/DashedOutlineBox.mjs +1 -1
- package/dist-esm/lib/editor/shapes/group/DashedOutlineBox.mjs.map +2 -2
- package/dist-esm/lib/globals/environment.mjs +45 -9
- package/dist-esm/lib/globals/environment.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCoarsePointer.mjs +15 -30
- package/dist-esm/lib/hooks/useCoarsePointer.mjs.map +2 -2
- package/dist-esm/lib/hooks/useZoomCss.mjs +4 -8
- package/dist-esm/lib/hooks/useZoomCss.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +3 -1
- package/dist-esm/lib/options.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/index.ts +1 -1
- package/src/lib/components/default-components/DefaultCanvas.tsx +3 -3
- package/src/lib/editor/Editor.ts +74 -5
- package/src/lib/editor/shapes/group/DashedOutlineBox.tsx +1 -1
- package/src/lib/globals/environment.ts +65 -10
- package/src/lib/hooks/useCoarsePointer.ts +16 -59
- package/src/lib/hooks/useZoomCss.ts +3 -8
- package/src/lib/options.ts +13 -0
- package/src/version.ts +3 -3
|
@@ -1,66 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { unsafe__withoutCapture } from '@tldraw/state'
|
|
2
|
+
import { useReactor } from '@tldraw/state-react'
|
|
3
|
+
import { tlenvReactive } from '../globals/environment'
|
|
3
4
|
import { useEditor } from './useEditor'
|
|
4
5
|
|
|
5
6
|
/** @internal */
|
|
6
7
|
export function useCoarsePointer() {
|
|
7
8
|
const editor = useEditor()
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
editor.updateInstanceState({ isCoarsePointer: isCoarseEvent })
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// we need `capture: true` here because the tldraw component itself stops propagation on
|
|
26
|
-
// pointer events it receives.
|
|
27
|
-
window.addEventListener('pointerdown', handlePointerDown, { capture: true })
|
|
28
|
-
|
|
29
|
-
// 2.
|
|
30
|
-
// We can also use the media query to detect / set the initial pointer type
|
|
31
|
-
// and update the state if the pointer type changes.
|
|
32
|
-
|
|
33
|
-
// We want the touch / mouse events to run even if the browser does not
|
|
34
|
-
// support matchMedia. We'll have to handle the media query changes
|
|
35
|
-
// conditionally in the code below.
|
|
36
|
-
const mql = window.matchMedia && window.matchMedia('(any-pointer: coarse)')
|
|
37
|
-
|
|
38
|
-
// This is a workaround for a Firefox bug where we don't correctly
|
|
39
|
-
// detect coarse VS fine pointer. For now, let's assume that you have a fine
|
|
40
|
-
// pointer if you're on Firefox on desktop.
|
|
41
|
-
const isForcedFinePointer = tlenv.isFirefox && !tlenv.isAndroid && !tlenv.isIos
|
|
42
|
-
|
|
43
|
-
const handleMediaQueryChange = () => {
|
|
44
|
-
const next = isForcedFinePointer ? false : mql.matches // get the value from the media query
|
|
45
|
-
if (isCoarse !== next) return // bail if the value hasn't changed
|
|
46
|
-
isCoarse = next // update the local value
|
|
47
|
-
editor.updateInstanceState({ isCoarsePointer: next }) // update the value in state
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (mql) {
|
|
51
|
-
// set up the listener
|
|
52
|
-
mql.addEventListener('change', handleMediaQueryChange)
|
|
53
|
-
|
|
54
|
-
// and run the handler once to set the initial value
|
|
55
|
-
handleMediaQueryChange()
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return () => {
|
|
59
|
-
window.removeEventListener('pointerdown', handlePointerDown, { capture: true })
|
|
60
|
-
|
|
61
|
-
if (mql) {
|
|
62
|
-
mql.removeEventListener('change', handleMediaQueryChange)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}, [editor])
|
|
10
|
+
// When the coarse pointer state changes, update the instance state
|
|
11
|
+
useReactor(
|
|
12
|
+
'coarse pointer change',
|
|
13
|
+
() => {
|
|
14
|
+
const isCoarsePointer = tlenvReactive.get().isCoarsePointer
|
|
15
|
+
const isInstanceStateCoarsePointer = unsafe__withoutCapture(
|
|
16
|
+
() => editor.getInstanceState().isCoarsePointer
|
|
17
|
+
)
|
|
18
|
+
if (isCoarsePointer === isInstanceStateCoarsePointer) return
|
|
19
|
+
editor.updateInstanceState({ isCoarsePointer: isCoarsePointer })
|
|
20
|
+
},
|
|
21
|
+
[editor]
|
|
22
|
+
)
|
|
66
23
|
}
|
|
@@ -12,14 +12,9 @@ export function useZoomCss() {
|
|
|
12
12
|
const setScale = (s: number) => container.style.setProperty('--tl-zoom', s.toString())
|
|
13
13
|
const setScaleDebounced = debounce(setScale, 100)
|
|
14
14
|
|
|
15
|
-
const scheduler = new EffectScheduler('useZoomCss', () =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
setScale(editor.getZoomLevel())
|
|
19
|
-
} else {
|
|
20
|
-
setScaleDebounced(editor.getZoomLevel())
|
|
21
|
-
}
|
|
22
|
-
})
|
|
15
|
+
const scheduler = new EffectScheduler('useZoomCss', () =>
|
|
16
|
+
setScale(editor.getEfficientZoomLevel())
|
|
17
|
+
)
|
|
23
18
|
|
|
24
19
|
scheduler.attach()
|
|
25
20
|
scheduler.execute()
|
package/src/lib/options.ts
CHANGED
|
@@ -87,6 +87,17 @@ export interface TldrawOptions {
|
|
|
87
87
|
* Branding name of the app, currently only used for adding aria-label for the application.
|
|
88
88
|
*/
|
|
89
89
|
readonly branding?: string
|
|
90
|
+
/**
|
|
91
|
+
* Whether to use debounced zoom level for certain rendering optimizations. When true,
|
|
92
|
+
* `editor.getDebouncedZoomLevel()` returns a cached zoom value while the camera is moving,
|
|
93
|
+
* reducing re-renders. When false, it always returns the current zoom level.
|
|
94
|
+
*/
|
|
95
|
+
readonly debouncedZoom: boolean
|
|
96
|
+
/**
|
|
97
|
+
* The number of shapes that must be on the page for the debounced zoom level to be used.
|
|
98
|
+
* Defaults to 300 shapes.
|
|
99
|
+
*/
|
|
100
|
+
readonly debouncedZoomThreshold: number
|
|
90
101
|
}
|
|
91
102
|
|
|
92
103
|
/** @public */
|
|
@@ -139,4 +150,6 @@ export const defaultTldrawOptions = {
|
|
|
139
150
|
enableToolbarKeyboardShortcuts: true,
|
|
140
151
|
maxFontsToLoadBeforeRender: Infinity,
|
|
141
152
|
nonce: undefined,
|
|
153
|
+
debouncedZoom: true,
|
|
154
|
+
debouncedZoomThreshold: 500,
|
|
142
155
|
} as const satisfies TldrawOptions
|
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 = '4.3.0-canary.
|
|
4
|
+
export const version = '4.3.0-canary.ef709265bb13'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2025-09-18T14:39:22.803Z',
|
|
7
|
-
minor: '2025-12-
|
|
8
|
-
patch: '2025-12-
|
|
7
|
+
minor: '2025-12-06T09:01:14.443Z',
|
|
8
|
+
patch: '2025-12-06T09:01:14.443Z',
|
|
9
9
|
}
|