@tldraw/editor 3.16.0-canary.ca347c5375a5 → 3.16.0-canary.cb4562244982
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 +80 -9
- package/dist-cjs/index.js +3 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +3 -1
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/MenuClickCapture.js +0 -5
- package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +1 -1
- package/dist-cjs/lib/components/default-components/DefaultScribble.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +9 -1
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
- package/dist-cjs/lib/config/TLUserPreferences.js +8 -2
- package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +46 -24
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +8 -3
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
- package/dist-cjs/lib/exports/getSvgJsx.js +1 -2
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +22 -20
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useStateAttribute.js +35 -0
- package/dist-cjs/lib/hooks/useStateAttribute.js.map +7 -0
- package/dist-cjs/lib/license/Watermark.js +6 -6
- package/dist-cjs/lib/license/Watermark.js.map +1 -1
- package/dist-cjs/lib/options.js +1 -0
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/utils/EditorAtom.js +45 -0
- package/dist-cjs/lib/utils/EditorAtom.js.map +7 -0
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +80 -9
- package/dist-esm/index.mjs +3 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +3 -1
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/MenuClickCapture.mjs +0 -5
- package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +1 -1
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +9 -1
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
- package/dist-esm/lib/config/TLUserPreferences.mjs +8 -2
- package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +46 -24
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +8 -3
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +23 -21
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useStateAttribute.mjs +15 -0
- package/dist-esm/lib/hooks/useStateAttribute.mjs.map +7 -0
- package/dist-esm/lib/license/Watermark.mjs +6 -6
- package/dist-esm/lib/license/Watermark.mjs.map +1 -1
- package/dist-esm/lib/options.mjs +1 -0
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/utils/EditorAtom.mjs +25 -0
- package/dist-esm/lib/utils/EditorAtom.mjs.map +7 -0
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +293 -288
- package/package.json +7 -7
- package/src/index.ts +2 -0
- package/src/lib/TldrawEditor.tsx +7 -5
- package/src/lib/components/MenuClickCapture.tsx +0 -8
- package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
- package/src/lib/components/default-components/DefaultScribble.tsx +1 -1
- package/src/lib/components/default-components/DefaultShapeIndicator.tsx +5 -1
- package/src/lib/config/TLUserPreferences.ts +7 -0
- package/src/lib/editor/Editor.ts +70 -47
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +13 -0
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +5 -0
- package/src/lib/editor/types/misc-types.ts +54 -1
- package/src/lib/exports/getSvgJsx.tsx +2 -2
- package/src/lib/hooks/useCanvasEvents.ts +36 -32
- package/src/lib/hooks/useStateAttribute.ts +15 -0
- package/src/lib/license/Watermark.tsx +6 -6
- package/src/lib/options.ts +2 -0
- package/src/lib/utils/EditorAtom.ts +37 -0
- package/src/version.ts +3 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tldraw/editor",
|
|
3
3
|
"description": "tldraw infinite canvas SDK (editor).",
|
|
4
|
-
"version": "3.16.0-canary.
|
|
4
|
+
"version": "3.16.0-canary.cb4562244982",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"@tiptap/core": "^2.9.1",
|
|
50
50
|
"@tiptap/pm": "^2.9.1",
|
|
51
51
|
"@tiptap/react": "^2.9.1",
|
|
52
|
-
"@tldraw/state": "3.16.0-canary.
|
|
53
|
-
"@tldraw/state-react": "3.16.0-canary.
|
|
54
|
-
"@tldraw/store": "3.16.0-canary.
|
|
55
|
-
"@tldraw/tlschema": "3.16.0-canary.
|
|
56
|
-
"@tldraw/utils": "3.16.0-canary.
|
|
57
|
-
"@tldraw/validate": "3.16.0-canary.
|
|
52
|
+
"@tldraw/state": "3.16.0-canary.cb4562244982",
|
|
53
|
+
"@tldraw/state-react": "3.16.0-canary.cb4562244982",
|
|
54
|
+
"@tldraw/store": "3.16.0-canary.cb4562244982",
|
|
55
|
+
"@tldraw/tlschema": "3.16.0-canary.cb4562244982",
|
|
56
|
+
"@tldraw/utils": "3.16.0-canary.cb4562244982",
|
|
57
|
+
"@tldraw/validate": "3.16.0-canary.cb4562244982",
|
|
58
58
|
"@types/core-js": "^2.5.8",
|
|
59
59
|
"@use-gesture/react": "^10.3.1",
|
|
60
60
|
"classnames": "^2.5.1",
|
package/src/index.ts
CHANGED
|
@@ -265,6 +265,7 @@ export {
|
|
|
265
265
|
type TLCameraMoveOptions,
|
|
266
266
|
type TLCameraOptions,
|
|
267
267
|
type TLExportType,
|
|
268
|
+
type TLGetShapeAtPointOptions,
|
|
268
269
|
type TLImageExportOptions,
|
|
269
270
|
type TLSvgExportOptions,
|
|
270
271
|
type TLSvgOptions,
|
|
@@ -450,6 +451,7 @@ export {
|
|
|
450
451
|
setPointerCapture,
|
|
451
452
|
stopEventPropagation,
|
|
452
453
|
} from './lib/utils/dom'
|
|
454
|
+
export { EditorAtom } from './lib/utils/EditorAtom'
|
|
453
455
|
export { getIncrementedName } from './lib/utils/getIncrementedName'
|
|
454
456
|
export { getPointerInfo } from './lib/utils/getPointerInfo'
|
|
455
457
|
export { getSvgPathFromPoints } from './lib/utils/getSvgPathFromPoints'
|
package/src/lib/TldrawEditor.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { MigrationSequence, Store } from '@tldraw/store'
|
|
2
2
|
import { TLShape, TLStore, TLStoreSnapshot } from '@tldraw/tlschema'
|
|
3
|
-
import {
|
|
3
|
+
import { annotateError, Required } from '@tldraw/utils'
|
|
4
4
|
import React, {
|
|
5
|
-
ReactNode,
|
|
6
5
|
memo,
|
|
6
|
+
ReactNode,
|
|
7
7
|
useCallback,
|
|
8
8
|
useEffect,
|
|
9
9
|
useLayoutEffect,
|
|
@@ -15,13 +15,13 @@ import React, {
|
|
|
15
15
|
|
|
16
16
|
import classNames from 'classnames'
|
|
17
17
|
import { version } from '../version'
|
|
18
|
-
import { OptionalErrorBoundary } from './components/ErrorBoundary'
|
|
19
18
|
import { DefaultErrorFallback } from './components/default-components/DefaultErrorFallback'
|
|
20
|
-
import {
|
|
19
|
+
import { OptionalErrorBoundary } from './components/ErrorBoundary'
|
|
21
20
|
import { TLStoreBaseOptions } from './config/createTLStore'
|
|
22
|
-
import {
|
|
21
|
+
import { createTLUser, TLUser } from './config/createTLUser'
|
|
23
22
|
import { TLAnyBindingUtilConstructor } from './config/defaultBindings'
|
|
24
23
|
import { TLAnyShapeUtilConstructor } from './config/defaultShapes'
|
|
24
|
+
import { TLEditorSnapshot } from './config/TLEditorSnapshot'
|
|
25
25
|
import { Editor } from './editor/Editor'
|
|
26
26
|
import { TLStateNodeConstructor } from './editor/tools/StateNode'
|
|
27
27
|
import { TLCameraOptions } from './editor/types/misc-types'
|
|
@@ -39,6 +39,7 @@ import { useForceUpdate } from './hooks/useForceUpdate'
|
|
|
39
39
|
import { useShallowObjectIdentity } from './hooks/useIdentity'
|
|
40
40
|
import { useLocalStore } from './hooks/useLocalStore'
|
|
41
41
|
import { useRefState } from './hooks/useRefState'
|
|
42
|
+
import { useStateAttribute } from './hooks/useStateAttribute'
|
|
42
43
|
import { useZoomCss } from './hooks/useZoomCss'
|
|
43
44
|
import { LicenseProvider } from './license/LicenseProvider'
|
|
44
45
|
import { Watermark } from './license/Watermark'
|
|
@@ -646,6 +647,7 @@ function Layout({ children, onMount }: { children: ReactNode; onMount?: TLOnMoun
|
|
|
646
647
|
useCursor()
|
|
647
648
|
useDarkMode()
|
|
648
649
|
useForceUpdate()
|
|
650
|
+
useStateAttribute()
|
|
649
651
|
useOnMount((editor) => {
|
|
650
652
|
const teardownStore = editor.store.props.onMount(editor)
|
|
651
653
|
const teardownCallback = onMount?.(editor)
|
|
@@ -50,12 +50,6 @@ export function MenuClickCapture() {
|
|
|
50
50
|
// Do nothing unless we're pointing
|
|
51
51
|
if (!rPointerState.current.isDown) return
|
|
52
52
|
|
|
53
|
-
// If we're already dragging, pass on the event as it is
|
|
54
|
-
if (rPointerState.current.isDragging) {
|
|
55
|
-
canvasEvents.onPointerMove?.(e)
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
53
|
if (
|
|
60
54
|
// We're pointing, but are we dragging?
|
|
61
55
|
Vec.Dist2(rPointerState.current.start, new Vec(e.clientX, e.clientY)) >
|
|
@@ -75,8 +69,6 @@ export function MenuClickCapture() {
|
|
|
75
69
|
clientY: y,
|
|
76
70
|
button: 0,
|
|
77
71
|
})
|
|
78
|
-
// call the pointer move with the current pointer position
|
|
79
|
-
canvasEvents.onPointerMove?.(e)
|
|
80
72
|
}
|
|
81
73
|
},
|
|
82
74
|
[canvasEvents, editor]
|
|
@@ -44,7 +44,7 @@ export function DefaultCollaboratorHint({
|
|
|
44
44
|
href={`#${cursorHintId}`}
|
|
45
45
|
color={color}
|
|
46
46
|
strokeWidth={3}
|
|
47
|
-
stroke="var(--color-background)"
|
|
47
|
+
stroke="var(--tl-color-background)"
|
|
48
48
|
/>
|
|
49
49
|
<use href={`#${cursorHintId}`} color={color} opacity={opacity} />
|
|
50
50
|
</svg>
|
|
@@ -21,7 +21,7 @@ export function DefaultScribble({ scribble, zoom, color, opacity, className }: T
|
|
|
21
21
|
<path
|
|
22
22
|
className="tl-scribble"
|
|
23
23
|
d={getSvgPathFromPoints(scribble.points, false)}
|
|
24
|
-
stroke={color ?? `var(--color-${scribble.color})`}
|
|
24
|
+
stroke={color ?? `var(--tl-color-${scribble.color})`}
|
|
25
25
|
fill="none"
|
|
26
26
|
strokeWidth={8 / zoom}
|
|
27
27
|
opacity={opacity ?? scribble.opacity}
|
|
@@ -87,7 +87,11 @@ export const DefaultShapeIndicator = memo(function DefaultShapeIndicator({
|
|
|
87
87
|
|
|
88
88
|
return (
|
|
89
89
|
<svg ref={rIndicator} className={classNames('tl-overlays__item', className)} aria-hidden="true">
|
|
90
|
-
<g
|
|
90
|
+
<g
|
|
91
|
+
className="tl-shape-indicator"
|
|
92
|
+
stroke={color ?? 'var(--tl-color-selected)'}
|
|
93
|
+
opacity={opacity}
|
|
94
|
+
>
|
|
91
95
|
<InnerIndicator editor={editor} id={shapeId} />
|
|
92
96
|
</g>
|
|
93
97
|
</svg>
|
|
@@ -24,6 +24,7 @@ export interface TLUserPreferences {
|
|
|
24
24
|
isWrapMode?: boolean | null
|
|
25
25
|
isDynamicSizeMode?: boolean | null
|
|
26
26
|
isPasteAtCursorMode?: boolean | null
|
|
27
|
+
showUiLabels?: boolean | null
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
interface UserDataSnapshot {
|
|
@@ -52,6 +53,7 @@ export const userTypeValidator: T.Validator<TLUserPreferences> = T.object<TLUser
|
|
|
52
53
|
isWrapMode: T.boolean.nullable().optional(),
|
|
53
54
|
isDynamicSizeMode: T.boolean.nullable().optional(),
|
|
54
55
|
isPasteAtCursorMode: T.boolean.nullable().optional(),
|
|
56
|
+
showUiLabels: T.boolean.nullable().optional(),
|
|
55
57
|
})
|
|
56
58
|
|
|
57
59
|
const Versions = {
|
|
@@ -64,6 +66,7 @@ const Versions = {
|
|
|
64
66
|
AllowSystemColorScheme: 7,
|
|
65
67
|
AddPasteAtCursor: 8,
|
|
66
68
|
AddKeyboardShortcuts: 9,
|
|
69
|
+
AddShowUiLabels: 10,
|
|
67
70
|
} as const
|
|
68
71
|
|
|
69
72
|
const CURRENT_VERSION = Math.max(...Object.values(Versions))
|
|
@@ -102,6 +105,9 @@ function migrateSnapshot(data: { version: number; user: any }) {
|
|
|
102
105
|
if (data.version < Versions.AddKeyboardShortcuts) {
|
|
103
106
|
data.user.areKeyboardShortcutsEnabled = true
|
|
104
107
|
}
|
|
108
|
+
if (data.version < Versions.AddShowUiLabels) {
|
|
109
|
+
data.user.showUiLabels = false
|
|
110
|
+
}
|
|
105
111
|
|
|
106
112
|
// finally
|
|
107
113
|
data.version = CURRENT_VERSION
|
|
@@ -150,6 +156,7 @@ export const defaultUserPreferences = Object.freeze({
|
|
|
150
156
|
isWrapMode: false,
|
|
151
157
|
isDynamicSizeMode: false,
|
|
152
158
|
isPasteAtCursorMode: false,
|
|
159
|
+
showUiLabels: false,
|
|
153
160
|
colorScheme: 'light',
|
|
154
161
|
}) satisfies Readonly<Omit<TLUserPreferences, 'id'>>
|
|
155
162
|
|
package/src/lib/editor/Editor.ts
CHANGED
|
@@ -176,6 +176,7 @@ import {
|
|
|
176
176
|
RequiredKeys,
|
|
177
177
|
TLCameraMoveOptions,
|
|
178
178
|
TLCameraOptions,
|
|
179
|
+
TLGetShapeAtPointOptions,
|
|
179
180
|
TLImageExportOptions,
|
|
180
181
|
TLSvgExportOptions,
|
|
181
182
|
TLUpdatePointerOptions,
|
|
@@ -5154,20 +5155,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5154
5155
|
*
|
|
5155
5156
|
* @returns The shape at the given point, or undefined if there is no shape at the point.
|
|
5156
5157
|
*/
|
|
5157
|
-
getShapeAtPoint(
|
|
5158
|
-
point: VecLike,
|
|
5159
|
-
opts = {} as {
|
|
5160
|
-
renderingOnly?: boolean
|
|
5161
|
-
margin?: number
|
|
5162
|
-
hitInside?: boolean
|
|
5163
|
-
hitLocked?: boolean
|
|
5164
|
-
// TODO: we probably need to rename this, we don't quite _always_
|
|
5165
|
-
// respect this esp. in the part below that does "Check labels first"
|
|
5166
|
-
hitLabels?: boolean
|
|
5167
|
-
hitFrameInside?: boolean
|
|
5168
|
-
filter?(shape: TLShape): boolean
|
|
5169
|
-
}
|
|
5170
|
-
): TLShape | undefined {
|
|
5158
|
+
getShapeAtPoint(point: VecLike, opts: TLGetShapeAtPointOptions = {}): TLShape | undefined {
|
|
5171
5159
|
const zoomLevel = this.getZoomLevel()
|
|
5172
5160
|
const viewportPageBounds = this.getViewportPageBounds()
|
|
5173
5161
|
const {
|
|
@@ -5179,6 +5167,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5179
5167
|
hitFrameInside = false,
|
|
5180
5168
|
} = opts
|
|
5181
5169
|
|
|
5170
|
+
const [innerMargin, outerMargin] = Array.isArray(margin) ? margin : [margin, margin]
|
|
5171
|
+
|
|
5182
5172
|
let inHollowSmallestArea = Infinity
|
|
5183
5173
|
let inHollowSmallestAreaHit: TLShape | null = null
|
|
5184
5174
|
|
|
@@ -5198,7 +5188,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5198
5188
|
return false
|
|
5199
5189
|
const pageMask = this.getShapeMask(shape)
|
|
5200
5190
|
if (pageMask && !pointInPolygon(point, pageMask)) return false
|
|
5201
|
-
if (filter
|
|
5191
|
+
if (filter && !filter(shape)) return false
|
|
5202
5192
|
return true
|
|
5203
5193
|
})
|
|
5204
5194
|
|
|
@@ -5224,13 +5214,18 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5224
5214
|
}
|
|
5225
5215
|
}
|
|
5226
5216
|
|
|
5227
|
-
if (this.isShapeOfType(shape, 'frame')) {
|
|
5217
|
+
if (this.isShapeOfType<TLFrameShape>(shape, 'frame')) {
|
|
5228
5218
|
// On the rare case that we've hit a frame (not its label), test again hitInside to be forced true;
|
|
5229
5219
|
// this prevents clicks from passing through the body of a frame to shapes behind it.
|
|
5230
5220
|
|
|
5231
5221
|
// If the hit is within the frame's outer margin, then select the frame
|
|
5232
|
-
const distance = geometry.distanceToPoint(pointInShapeSpace,
|
|
5233
|
-
if (
|
|
5222
|
+
const distance = geometry.distanceToPoint(pointInShapeSpace, hitFrameInside)
|
|
5223
|
+
if (
|
|
5224
|
+
hitFrameInside
|
|
5225
|
+
? (distance > 0 && distance <= outerMargin) ||
|
|
5226
|
+
(distance <= 0 && distance > -innerMargin)
|
|
5227
|
+
: distance > 0 && distance <= outerMargin
|
|
5228
|
+
) {
|
|
5234
5229
|
return inMarginClosestToEdgeHit || shape
|
|
5235
5230
|
}
|
|
5236
5231
|
|
|
@@ -5269,11 +5264,11 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5269
5264
|
// If the margin is zero and the geometry has a very small width or height,
|
|
5270
5265
|
// then check the actual distance. This is to prevent a bug where straight
|
|
5271
5266
|
// lines would never pass the broad phase (point-in-bounds) check.
|
|
5272
|
-
if (
|
|
5267
|
+
if (outerMargin === 0 && (geometry.bounds.w < 1 || geometry.bounds.h < 1)) {
|
|
5273
5268
|
distance = geometry.distanceToPoint(pointInShapeSpace, hitInside)
|
|
5274
5269
|
} else {
|
|
5275
5270
|
// Broad phase
|
|
5276
|
-
if (geometry.bounds.containsPoint(pointInShapeSpace,
|
|
5271
|
+
if (geometry.bounds.containsPoint(pointInShapeSpace, outerMargin)) {
|
|
5277
5272
|
// Narrow phase (actual distance)
|
|
5278
5273
|
distance = geometry.distanceToPoint(pointInShapeSpace, hitInside)
|
|
5279
5274
|
} else {
|
|
@@ -5288,7 +5283,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5288
5283
|
// the shape or negative if inside of the shape. If the distance
|
|
5289
5284
|
// is greater than the margin, then it's a miss. Otherwise...
|
|
5290
5285
|
|
|
5291
|
-
|
|
5286
|
+
// Are we close to the shape's edge?
|
|
5287
|
+
if (distance <= outerMargin || (hitInside && distance <= 0 && distance > -innerMargin)) {
|
|
5292
5288
|
if (geometry.isFilled || (isGroup && geometry.children[0].isFilled)) {
|
|
5293
5289
|
// If the shape is filled, then it's a hit. Remember, we're
|
|
5294
5290
|
// starting from the TOP-MOST shape in z-index order, so any
|
|
@@ -5298,11 +5294,21 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5298
5294
|
// If the shape is bigger than the viewport, then skip it.
|
|
5299
5295
|
if (this.getShapePageBounds(shape)!.contains(viewportPageBounds)) continue
|
|
5300
5296
|
|
|
5301
|
-
//
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5297
|
+
// If we're close to the edge of the shape, and if it's the closest edge among
|
|
5298
|
+
// all the edges that we've gotten close to so far, then we will want to hit the
|
|
5299
|
+
// shape unless we hit something else or closer in later iterations.
|
|
5300
|
+
if (
|
|
5301
|
+
hitInside
|
|
5302
|
+
? // On hitInside, the distance will be negative for hits inside
|
|
5303
|
+
// If the distance is positive, check against the outer margin
|
|
5304
|
+
(distance > 0 && distance <= outerMargin) ||
|
|
5305
|
+
// If the distance is negative, check against the inner margin
|
|
5306
|
+
(distance <= 0 && distance > -innerMargin)
|
|
5307
|
+
: // If hitInside is false, then sadly _we do not know_ whether the
|
|
5308
|
+
// point is inside or outside of the shape, so we check against
|
|
5309
|
+
// the max of the two margins
|
|
5310
|
+
Math.abs(distance) <= Math.max(innerMargin, outerMargin)
|
|
5311
|
+
) {
|
|
5306
5312
|
if (Math.abs(distance) < inMarginClosestToEdgeDistance) {
|
|
5307
5313
|
inMarginClosestToEdgeDistance = Math.abs(distance)
|
|
5308
5314
|
inMarginClosestToEdgeHit = shape
|
|
@@ -5324,6 +5330,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5324
5330
|
} else {
|
|
5325
5331
|
// For open shapes (e.g. lines or draw shapes) always use the margin.
|
|
5326
5332
|
// If the distance is less than the margin, return the shape as the hit.
|
|
5333
|
+
// Use the editor's configurable hit test margin.
|
|
5327
5334
|
if (distance < this.options.hitTestMargin / zoomLevel) {
|
|
5328
5335
|
return shape
|
|
5329
5336
|
}
|
|
@@ -6326,7 +6333,17 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6326
6333
|
|
|
6327
6334
|
this.createShapes(shapesToCreate)
|
|
6328
6335
|
this.createBindings(bindingsToCreate)
|
|
6329
|
-
|
|
6336
|
+
|
|
6337
|
+
this.setSelectedShapes(
|
|
6338
|
+
compact(
|
|
6339
|
+
ids.map((oldId) => {
|
|
6340
|
+
const newId = shapeIds.get(oldId)
|
|
6341
|
+
if (!newId) return null
|
|
6342
|
+
if (!this.getShape(newId)) return null
|
|
6343
|
+
return newId
|
|
6344
|
+
})
|
|
6345
|
+
)
|
|
6346
|
+
)
|
|
6330
6347
|
|
|
6331
6348
|
if (offset !== undefined) {
|
|
6332
6349
|
// If we've offset the duplicated shapes, check to see whether their new bounds is entirely
|
|
@@ -7380,7 +7397,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7380
7397
|
if (
|
|
7381
7398
|
!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
7382
7399
|
type: 'stretch',
|
|
7383
|
-
shapes: shapesToStretchFirstPass,
|
|
7384
7400
|
})
|
|
7385
7401
|
) {
|
|
7386
7402
|
continue
|
|
@@ -7851,25 +7867,32 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7851
7867
|
) {
|
|
7852
7868
|
let parentId: TLParentId = this.getFocusedGroupId()
|
|
7853
7869
|
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
|
|
7870
|
+
const isPositioned = partial.x !== undefined && partial.y !== undefined
|
|
7871
|
+
|
|
7872
|
+
// If the shape has been explicitly positioned, we'll try to find a parent at
|
|
7873
|
+
// that position. If not, we'll assume the user isn't deliberately placing the
|
|
7874
|
+
// shape and the positioning will be handled later by another system.
|
|
7875
|
+
if (isPositioned) {
|
|
7876
|
+
for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
|
|
7877
|
+
const parent = currentPageShapesSorted[i]
|
|
7878
|
+
const util = this.getShapeUtil(parent)
|
|
7879
|
+
if (
|
|
7880
|
+
util.canReceiveNewChildrenOfType(parent, partial.type) &&
|
|
7881
|
+
!this.isShapeHidden(parent) &&
|
|
7882
|
+
this.isPointInShape(
|
|
7883
|
+
parent,
|
|
7884
|
+
// If no parent is provided, then we can treat the
|
|
7885
|
+
// shape's provided x/y as being in the page's space.
|
|
7886
|
+
{ x: partial.x ?? 0, y: partial.y ?? 0 },
|
|
7887
|
+
{
|
|
7888
|
+
margin: 0,
|
|
7889
|
+
hitInside: true,
|
|
7890
|
+
}
|
|
7891
|
+
)
|
|
7892
|
+
) {
|
|
7893
|
+
parentId = parent.id
|
|
7894
|
+
break
|
|
7895
|
+
}
|
|
7873
7896
|
}
|
|
7874
7897
|
}
|
|
7875
7898
|
|
|
@@ -25,6 +25,7 @@ describe('UserPreferencesManager', () => {
|
|
|
25
25
|
locale: 'en',
|
|
26
26
|
animationSpeed: 1,
|
|
27
27
|
areKeyboardShortcutsEnabled: true,
|
|
28
|
+
showUiLabels: false,
|
|
28
29
|
edgeScrollSpeed: 1,
|
|
29
30
|
colorScheme: 'light',
|
|
30
31
|
isSnapMode: false,
|
|
@@ -231,6 +232,7 @@ describe('UserPreferencesManager', () => {
|
|
|
231
232
|
color: mockUserPreferences.color,
|
|
232
233
|
animationSpeed: mockUserPreferences.animationSpeed,
|
|
233
234
|
areKeyboardShortcutsEnabled: mockUserPreferences.areKeyboardShortcutsEnabled,
|
|
235
|
+
showUiLabels: mockUserPreferences.showUiLabels,
|
|
234
236
|
isSnapMode: mockUserPreferences.isSnapMode,
|
|
235
237
|
colorScheme: mockUserPreferences.colorScheme,
|
|
236
238
|
isDarkMode: false, // light mode
|
|
@@ -379,6 +381,17 @@ describe('UserPreferencesManager', () => {
|
|
|
379
381
|
})
|
|
380
382
|
})
|
|
381
383
|
|
|
384
|
+
describe('getShowUiLabels', () => {
|
|
385
|
+
it('should return user show ui labels setting', () => {
|
|
386
|
+
expect(userPreferencesManager.getShowUiLabels()).toBe(mockUserPreferences.showUiLabels)
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
it('should return default show ui labels when null', () => {
|
|
390
|
+
userPreferencesAtom.set({ ...mockUserPreferences, showUiLabels: null })
|
|
391
|
+
expect(userPreferencesManager.getShowUiLabels()).toBe(defaultUserPreferences.showUiLabels)
|
|
392
|
+
})
|
|
393
|
+
})
|
|
394
|
+
|
|
382
395
|
describe('getEdgeScrollSpeed', () => {
|
|
383
396
|
it('should return user edge scroll speed', () => {
|
|
384
397
|
expect(userPreferencesManager.getEdgeScrollSpeed()).toBe(
|
|
@@ -49,6 +49,7 @@ export class UserPreferencesManager {
|
|
|
49
49
|
isDarkMode: this.getIsDarkMode(),
|
|
50
50
|
isWrapMode: this.getIsWrapMode(),
|
|
51
51
|
isDynamicResizeMode: this.getIsDynamicResizeMode(),
|
|
52
|
+
showUiLabels: this.getShowUiLabels(),
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -119,4 +120,8 @@ export class UserPreferencesManager {
|
|
|
119
120
|
defaultUserPreferences.isPasteAtCursorMode
|
|
120
121
|
)
|
|
121
122
|
}
|
|
123
|
+
|
|
124
|
+
@computed getShowUiLabels() {
|
|
125
|
+
return this.user.userPreferences.get().showUiLabels ?? defaultUserPreferences.showUiLabels
|
|
126
|
+
}
|
|
122
127
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BoxModel } from '@tldraw/tlschema'
|
|
1
|
+
import { BoxModel, TLShape } from '@tldraw/tlschema'
|
|
2
2
|
import { Box } from '../../primitives/Box'
|
|
3
3
|
import { VecLike } from '../../primitives/Vec'
|
|
4
4
|
|
|
@@ -206,3 +206,56 @@ export interface TLUpdatePointerOptions {
|
|
|
206
206
|
isPen?: boolean
|
|
207
207
|
button?: number
|
|
208
208
|
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Options to {@link Editor.getShapeAtPoint}.
|
|
212
|
+
*
|
|
213
|
+
* @public
|
|
214
|
+
*/
|
|
215
|
+
export interface TLGetShapeAtPointOptions {
|
|
216
|
+
/**
|
|
217
|
+
* The margin to apply to the shape.
|
|
218
|
+
* If a number, it will be applied to both the inside and outside of the shape.
|
|
219
|
+
* If an array, the first element will be applied to the inside of the shape, and the second element will be applied to the outside.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* // Get the shape at the center of the screen
|
|
224
|
+
* const shape = editor.getShapeAtProps({
|
|
225
|
+
* margin: 10,
|
|
226
|
+
* })
|
|
227
|
+
*
|
|
228
|
+
* // Get the shape at the center of the screen with a 10px inner margin and a 5px outer margin
|
|
229
|
+
* const shape = editor.getShapeAtProps({
|
|
230
|
+
* margin: [10, 5],
|
|
231
|
+
* })
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
margin?: number | [number, number]
|
|
235
|
+
/**
|
|
236
|
+
* Whether to register hits inside of shapes (beyond the margin), such as the inside of a solid shape.
|
|
237
|
+
*/
|
|
238
|
+
hitInside?: boolean
|
|
239
|
+
/**
|
|
240
|
+
* Whether to register hits on locked shapes.
|
|
241
|
+
*/
|
|
242
|
+
hitLocked?: boolean
|
|
243
|
+
/**
|
|
244
|
+
* Whether to register hits on labels.
|
|
245
|
+
*/
|
|
246
|
+
hitLabels?: boolean
|
|
247
|
+
/**
|
|
248
|
+
* Whether to only return hits on shapes that are currently being rendered.
|
|
249
|
+
* todo: rename this to hitCulled or hitNotRendering
|
|
250
|
+
*/
|
|
251
|
+
renderingOnly?: boolean
|
|
252
|
+
/**
|
|
253
|
+
* Whether to register hits on the inside of frame shapes.
|
|
254
|
+
* todo: rename this to hitInsideFrames
|
|
255
|
+
*/
|
|
256
|
+
hitFrameInside?: boolean
|
|
257
|
+
/**
|
|
258
|
+
* A filter function to apply to the shapes.
|
|
259
|
+
*/
|
|
260
|
+
filter?(shape: TLShape): boolean
|
|
261
|
+
}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
TLGroupShape,
|
|
5
5
|
TLShape,
|
|
6
6
|
TLShapeId,
|
|
7
|
+
getColorValue,
|
|
7
8
|
getDefaultColorTheme,
|
|
8
9
|
} from '@tldraw/tlschema'
|
|
9
10
|
import { hasOwnProperty, promiseWithResolve, uniqueId } from '@tldraw/utils'
|
|
@@ -373,8 +374,7 @@ function SvgExport({
|
|
|
373
374
|
| { options: { showColors: boolean } }
|
|
374
375
|
if (frameShapeUtil?.options.showColors) {
|
|
375
376
|
const shape = editor.getShape(singleFrameShapeId)! as TLFrameShape
|
|
376
|
-
|
|
377
|
-
backgroundColor = color.frame.fill
|
|
377
|
+
backgroundColor = getColorValue(theme, shape.props.color, 'frameFill')
|
|
378
378
|
} else {
|
|
379
379
|
backgroundColor = theme.solid
|
|
380
380
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useValue } from '@tldraw/state-react'
|
|
2
|
-
import React, { useMemo } from 'react'
|
|
2
|
+
import React, { useEffect, useMemo } from 'react'
|
|
3
3
|
import { RIGHT_MOUSE_BUTTON } from '../constants'
|
|
4
4
|
import {
|
|
5
5
|
preventDefault,
|
|
@@ -16,9 +16,6 @@ export function useCanvasEvents() {
|
|
|
16
16
|
|
|
17
17
|
const events = useMemo(
|
|
18
18
|
function canvasEvents() {
|
|
19
|
-
// Track the last screen point
|
|
20
|
-
let lastX: number, lastY: number
|
|
21
|
-
|
|
22
19
|
function onPointerDown(e: React.PointerEvent) {
|
|
23
20
|
if ((e as any).isKilled) return
|
|
24
21
|
|
|
@@ -44,35 +41,9 @@ export function useCanvasEvents() {
|
|
|
44
41
|
})
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
function onPointerMove(e: React.PointerEvent) {
|
|
48
|
-
if ((e as any).isKilled) return
|
|
49
|
-
|
|
50
|
-
if (e.clientX === lastX && e.clientY === lastY) return
|
|
51
|
-
lastX = e.clientX
|
|
52
|
-
lastY = e.clientY
|
|
53
|
-
|
|
54
|
-
// For tools that benefit from a higher fidelity of events,
|
|
55
|
-
// we dispatch the coalesced events.
|
|
56
|
-
// N.B. Sometimes getCoalescedEvents isn't present on iOS, ugh.
|
|
57
|
-
const events =
|
|
58
|
-
currentTool.useCoalescedEvents && e.nativeEvent.getCoalescedEvents
|
|
59
|
-
? e.nativeEvent.getCoalescedEvents()
|
|
60
|
-
: [e]
|
|
61
|
-
for (const singleEvent of events) {
|
|
62
|
-
editor.dispatch({
|
|
63
|
-
type: 'pointer',
|
|
64
|
-
target: 'canvas',
|
|
65
|
-
name: 'pointer_move',
|
|
66
|
-
...getPointerInfo(singleEvent),
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
44
|
function onPointerUp(e: React.PointerEvent) {
|
|
72
45
|
if ((e as any).isKilled) return
|
|
73
46
|
if (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return
|
|
74
|
-
lastX = e.clientX
|
|
75
|
-
lastY = e.clientY
|
|
76
47
|
|
|
77
48
|
releasePointerCapture(e.currentTarget, e)
|
|
78
49
|
|
|
@@ -158,7 +129,6 @@ export function useCanvasEvents() {
|
|
|
158
129
|
|
|
159
130
|
return {
|
|
160
131
|
onPointerDown,
|
|
161
|
-
onPointerMove,
|
|
162
132
|
onPointerUp,
|
|
163
133
|
onPointerEnter,
|
|
164
134
|
onPointerLeave,
|
|
@@ -169,8 +139,42 @@ export function useCanvasEvents() {
|
|
|
169
139
|
onClick,
|
|
170
140
|
}
|
|
171
141
|
},
|
|
172
|
-
[editor
|
|
142
|
+
[editor]
|
|
173
143
|
)
|
|
174
144
|
|
|
145
|
+
// onPointerMove is special: where we're only interested in the other events when they're
|
|
146
|
+
// happening _on_ the canvas (as opposed to outside of it, or on UI floating over it), we want
|
|
147
|
+
// the pointer position to be up to date regardless of whether it's over the tldraw canvas or
|
|
148
|
+
// not. So instead of returning a listener to be attached to the canvas, we directly attach a
|
|
149
|
+
// listener to the whole document instead.
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
let lastX: number, lastY: number
|
|
152
|
+
|
|
153
|
+
function onPointerMove(e: PointerEvent) {
|
|
154
|
+
if (e.clientX === lastX && e.clientY === lastY) return
|
|
155
|
+
lastX = e.clientX
|
|
156
|
+
lastY = e.clientY
|
|
157
|
+
|
|
158
|
+
// For tools that benefit from a higher fidelity of events,
|
|
159
|
+
// we dispatch the coalesced events.
|
|
160
|
+
// N.B. Sometimes getCoalescedEvents isn't present on iOS, ugh.
|
|
161
|
+
const events =
|
|
162
|
+
currentTool.useCoalescedEvents && e.getCoalescedEvents ? e.getCoalescedEvents() : [e]
|
|
163
|
+
for (const singleEvent of events) {
|
|
164
|
+
editor.dispatch({
|
|
165
|
+
type: 'pointer',
|
|
166
|
+
target: 'canvas',
|
|
167
|
+
name: 'pointer_move',
|
|
168
|
+
...getPointerInfo(singleEvent),
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
document.body.addEventListener('pointermove', onPointerMove)
|
|
174
|
+
return () => {
|
|
175
|
+
document.body.removeEventListener('pointermove', onPointerMove)
|
|
176
|
+
}
|
|
177
|
+
}, [editor, currentTool])
|
|
178
|
+
|
|
175
179
|
return events
|
|
176
180
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { react } from '@tldraw/state'
|
|
2
|
+
import { useLayoutEffect } from 'react'
|
|
3
|
+
import { useEditor } from './useEditor'
|
|
4
|
+
|
|
5
|
+
export function useStateAttribute() {
|
|
6
|
+
const editor = useEditor()
|
|
7
|
+
|
|
8
|
+
// we use a layout effect because we don't want there to be any perceptible delay between the
|
|
9
|
+
// editor mounting and this attribute being applied, because styles may depend on it:
|
|
10
|
+
useLayoutEffect(() => {
|
|
11
|
+
return react('stateAttribute', () => {
|
|
12
|
+
editor.getContainer().setAttribute('data-state', editor.getPath())
|
|
13
|
+
})
|
|
14
|
+
}, [editor])
|
|
15
|
+
}
|