tldraw 4.4.0-canary.afdcafe834b3 → 4.4.0-canary.b80d167101d1
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 +113 -2
- package/dist-cjs/index.js +10 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/bindings/arrow/ArrowBindingUtil.js +6 -1
- package/dist-cjs/lib/bindings/arrow/ArrowBindingUtil.js.map +2 -2
- package/dist-cjs/lib/defaultSideEffects.js +8 -0
- package/dist-cjs/lib/defaultSideEffects.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js +2 -1
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js.map +2 -2
- package/dist-cjs/lib/tools/selection-logic/updateHoveredShapeId.js +26 -3
- package/dist-cjs/lib/tools/selection-logic/updateHoveredShapeId.js.map +3 -3
- package/dist-cjs/lib/ui/components/primitives/TldrawUiSelect.js +144 -0
- package/dist-cjs/lib/ui/components/primitives/TldrawUiSelect.js.map +7 -0
- package/dist-cjs/lib/ui/context/actions.js +3 -0
- package/dist-cjs/lib/ui/context/actions.js.map +2 -2
- package/dist-cjs/lib/ui/context/events.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 +113 -2
- package/dist-esm/index.mjs +17 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/bindings/arrow/ArrowBindingUtil.mjs +6 -1
- package/dist-esm/lib/bindings/arrow/ArrowBindingUtil.mjs.map +2 -2
- package/dist-esm/lib/defaultSideEffects.mjs +8 -0
- package/dist-esm/lib/defaultSideEffects.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs +2 -1
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs.map +2 -2
- package/dist-esm/lib/tools/selection-logic/updateHoveredShapeId.mjs +26 -3
- package/dist-esm/lib/tools/selection-logic/updateHoveredShapeId.mjs.map +3 -3
- package/dist-esm/lib/ui/components/primitives/TldrawUiSelect.mjs +114 -0
- package/dist-esm/lib/ui/components/primitives/TldrawUiSelect.mjs.map +7 -0
- package/dist-esm/lib/ui/context/actions.mjs +3 -0
- package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
- package/dist-esm/lib/ui/context/events.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 +4 -5
- package/src/index.ts +15 -1
- package/src/lib/bindings/arrow/ArrowBindingUtil.ts +12 -0
- package/src/lib/defaultSideEffects.ts +8 -0
- package/src/lib/shapes/shared/RichTextLabel.tsx +1 -0
- package/src/lib/tools/selection-logic/updateHoveredShapeId.ts +54 -5
- package/src/lib/ui/components/primitives/TldrawUiSelect.tsx +211 -0
- package/src/lib/ui/context/actions.tsx +3 -0
- package/src/lib/ui/context/events.tsx +0 -1
- package/src/lib/ui/version.ts +3 -3
- package/src/lib/ui.css +46 -0
- package/src/test/commands/__snapshots__/getSvgString.test.ts.snap +2 -2
- package/src/test/commands/cameraState.test.ts +109 -0
- package/tldraw.css +51 -0
package/src/index.ts
CHANGED
|
@@ -400,6 +400,7 @@ export {
|
|
|
400
400
|
TldrawUiDropdownMenuItem,
|
|
401
401
|
TldrawUiDropdownMenuRoot,
|
|
402
402
|
TldrawUiDropdownMenuSub,
|
|
403
|
+
TldrawUiDropdownMenuSubContent,
|
|
403
404
|
TldrawUiDropdownMenuSubTrigger,
|
|
404
405
|
TldrawUiDropdownMenuTrigger,
|
|
405
406
|
type TLUiDropdownMenuCheckboxItemProps,
|
|
@@ -407,6 +408,7 @@ export {
|
|
|
407
408
|
type TLUiDropdownMenuGroupProps,
|
|
408
409
|
type TLUiDropdownMenuItemProps,
|
|
409
410
|
type TLUiDropdownMenuRootProps,
|
|
411
|
+
type TLUiDropdownMenuSubContentProps,
|
|
410
412
|
type TLUiDropdownMenuSubProps,
|
|
411
413
|
type TLUiDropdownMenuSubTriggerProps,
|
|
412
414
|
type TLUiDropdownMenuTriggerProps,
|
|
@@ -426,6 +428,18 @@ export {
|
|
|
426
428
|
type TLUiPopoverProps,
|
|
427
429
|
type TLUiPopoverTriggerProps,
|
|
428
430
|
} from './lib/ui/components/primitives/TldrawUiPopover'
|
|
431
|
+
export {
|
|
432
|
+
TldrawUiSelect,
|
|
433
|
+
TldrawUiSelectContent,
|
|
434
|
+
TldrawUiSelectItem,
|
|
435
|
+
TldrawUiSelectTrigger,
|
|
436
|
+
TldrawUiSelectValue,
|
|
437
|
+
type TLUiSelectContentProps,
|
|
438
|
+
type TLUiSelectItemProps,
|
|
439
|
+
type TLUiSelectProps,
|
|
440
|
+
type TLUiSelectTriggerProps,
|
|
441
|
+
type TLUiSelectValueProps,
|
|
442
|
+
} from './lib/ui/components/primitives/TldrawUiSelect'
|
|
429
443
|
export { TldrawUiSlider, type TLUiSliderProps } from './lib/ui/components/primitives/TldrawUiSlider'
|
|
430
444
|
export {
|
|
431
445
|
TldrawUiToolbar,
|
|
@@ -671,7 +685,7 @@ export {
|
|
|
671
685
|
type TLUiTranslationContextType,
|
|
672
686
|
type TLUiTranslationProviderProps,
|
|
673
687
|
} from './lib/ui/hooks/useTranslation/useTranslation'
|
|
674
|
-
export { type TLUiIconType } from './lib/ui/icon-types'
|
|
688
|
+
export { iconTypes, type TLUiIconType } from './lib/ui/icon-types'
|
|
675
689
|
export { useDefaultHelpers, type TLUiOverrideHelpers, type TLUiOverrides } from './lib/ui/overrides'
|
|
676
690
|
export { TldrawUi, TldrawUiInFrontOfTheCanvas, type TldrawUiProps } from './lib/ui/TldrawUi'
|
|
677
691
|
export { containBoxSize, downsizeImage, type BoxWidthHeight } from './lib/utils/assets/assets'
|
|
@@ -58,8 +58,20 @@ export class ArrowBindingUtil extends BindingUtil<TLArrowBinding> {
|
|
|
58
58
|
|
|
59
59
|
// when the arrow itself changes
|
|
60
60
|
override onAfterChangeFromShape({
|
|
61
|
+
shapeBefore,
|
|
61
62
|
shapeAfter,
|
|
63
|
+
reason,
|
|
62
64
|
}: BindingOnShapeChangeOptions<TLArrowBinding>): void {
|
|
65
|
+
// When translating arrows together with their bound shapes, only x/y changes.
|
|
66
|
+
// In this case, bindings remain valid and no reparenting is needed.
|
|
67
|
+
// This is a significant performance optimization when moving many bound shapes.
|
|
68
|
+
if (
|
|
69
|
+
reason !== 'ancestry' &&
|
|
70
|
+
shapeBefore.parentId === shapeAfter.parentId &&
|
|
71
|
+
shapeBefore.index === shapeAfter.index
|
|
72
|
+
) {
|
|
73
|
+
return
|
|
74
|
+
}
|
|
63
75
|
arrowDidUpdate(this.editor, shapeAfter as TLArrowShape)
|
|
64
76
|
}
|
|
65
77
|
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { Editor } from '@tldraw/editor'
|
|
2
|
+
import { updateHoveredShapeId } from './tools/selection-logic/updateHoveredShapeId'
|
|
2
3
|
|
|
3
4
|
/** @public */
|
|
4
5
|
export function registerDefaultSideEffects(editor: Editor) {
|
|
5
6
|
return editor.sideEffects.register({
|
|
7
|
+
instance: {
|
|
8
|
+
afterChange: (prev, next) => {
|
|
9
|
+
if (prev.cameraState !== next.cameraState && next.cameraState === 'idle') {
|
|
10
|
+
updateHoveredShapeId(editor)
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
},
|
|
6
14
|
instance_page_state: {
|
|
7
15
|
afterChange: (prev, next) => {
|
|
8
16
|
if (prev.croppingShapeId !== next.croppingShapeId) {
|
|
@@ -1,7 +1,27 @@
|
|
|
1
|
-
import { Editor, TLShape, throttle } from '@tldraw/editor'
|
|
1
|
+
import { Editor, TLShape, TLShapeId, throttle } from '@tldraw/editor'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/*
|
|
4
|
+
Perf optimization: Skip hover updates while panning.
|
|
5
|
+
|
|
6
|
+
Hit-testing shapes is expensive in large documents. When panning, we don't need
|
|
7
|
+
continuous hover updates - we just need to resume when the camera stops.
|
|
8
|
+
|
|
9
|
+
The logic:
|
|
10
|
+
1. Camera idle → update hover normally, unlock
|
|
11
|
+
2. Camera moving + locked → skip entirely (no hit-testing)
|
|
12
|
+
3. Camera moving + no current hover → lock immediately
|
|
13
|
+
4. Camera moving + same shape → keep current hover (no change needed)
|
|
14
|
+
5. Camera moving + different shape → clear hover and lock
|
|
15
|
+
|
|
16
|
+
This means: when you start panning over a shape, it stays hovered until
|
|
17
|
+
your cursor moves off it, then hover clears and we stop hit-testing until
|
|
18
|
+
the camera stops.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// Track per-editor state for hover updates during camera movement
|
|
22
|
+
const hoverLockedEditors = new WeakMap<Editor, boolean>()
|
|
23
|
+
|
|
24
|
+
function getShapeToHover(editor: Editor): TLShapeId | null {
|
|
5
25
|
const hitShape = editor.getShapeAtPoint(editor.inputs.getCurrentPagePoint(), {
|
|
6
26
|
hitInside: false,
|
|
7
27
|
hitLabels: false,
|
|
@@ -9,7 +29,7 @@ function _updateHoveredShapeId(editor: Editor) {
|
|
|
9
29
|
renderingOnly: true,
|
|
10
30
|
})
|
|
11
31
|
|
|
12
|
-
if (!hitShape) return
|
|
32
|
+
if (!hitShape) return null
|
|
13
33
|
|
|
14
34
|
let shapeToHover: TLShape | undefined = undefined
|
|
15
35
|
|
|
@@ -28,7 +48,36 @@ function _updateHoveredShapeId(editor: Editor) {
|
|
|
28
48
|
}
|
|
29
49
|
}
|
|
30
50
|
|
|
31
|
-
return
|
|
51
|
+
return shapeToHover.id
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _updateHoveredShapeId(editor: Editor) {
|
|
55
|
+
const cameraMoving = editor.getCameraState() === 'moving'
|
|
56
|
+
|
|
57
|
+
if (!cameraMoving) {
|
|
58
|
+
hoverLockedEditors.set(editor, false)
|
|
59
|
+
const nextHoveredId = getShapeToHover(editor)
|
|
60
|
+
return editor.setHoveredShape(nextHoveredId)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (hoverLockedEditors.get(editor)) {
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const currentHoveredId = editor.getHoveredShapeId()
|
|
68
|
+
|
|
69
|
+
if (!currentHoveredId) {
|
|
70
|
+
hoverLockedEditors.set(editor, true)
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const nextHoveredId = getShapeToHover(editor)
|
|
75
|
+
if (nextHoveredId === currentHoveredId) {
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
editor.setHoveredShape(null)
|
|
80
|
+
hoverLockedEditors.set(editor, true)
|
|
32
81
|
}
|
|
33
82
|
|
|
34
83
|
/** @internal */
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { useContainer } from '@tldraw/editor'
|
|
2
|
+
import classNames from 'classnames'
|
|
3
|
+
import { Select as _Select } from 'radix-ui'
|
|
4
|
+
import * as React from 'react'
|
|
5
|
+
import { useMenuIsOpen } from '../../hooks/useMenuIsOpen'
|
|
6
|
+
import { TLUiIconType } from '../../icon-types'
|
|
7
|
+
import { TldrawUiIcon } from './TldrawUiIcon'
|
|
8
|
+
|
|
9
|
+
/* --------------------- Root --------------------- */
|
|
10
|
+
|
|
11
|
+
/** @public */
|
|
12
|
+
export interface TLUiSelectProps {
|
|
13
|
+
id: string
|
|
14
|
+
value: string
|
|
15
|
+
onValueChange(value: string): void
|
|
16
|
+
onOpenChange?(isOpen: boolean): void
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
className?: string
|
|
19
|
+
children: React.ReactNode
|
|
20
|
+
'data-testid'?: string
|
|
21
|
+
'aria-label'?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A select dropdown component.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* <TldrawUiSelect id="my-select" value={value} onValueChange={setValue}>
|
|
30
|
+
* <TldrawUiSelectTrigger>
|
|
31
|
+
* <TldrawUiSelectValue placeholder="Select..." />
|
|
32
|
+
* </TldrawUiSelectTrigger>
|
|
33
|
+
* <TldrawUiSelectContent>
|
|
34
|
+
* <TldrawUiSelectItem value="one" label="One" />
|
|
35
|
+
* <TldrawUiSelectItem value="two" label="Two" />
|
|
36
|
+
* </TldrawUiSelectContent>
|
|
37
|
+
* </TldrawUiSelect>
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
* @react
|
|
42
|
+
*/
|
|
43
|
+
export function TldrawUiSelect({
|
|
44
|
+
id,
|
|
45
|
+
value,
|
|
46
|
+
onValueChange,
|
|
47
|
+
onOpenChange,
|
|
48
|
+
disabled,
|
|
49
|
+
className,
|
|
50
|
+
children,
|
|
51
|
+
'data-testid': dataTestId,
|
|
52
|
+
'aria-label': ariaLabel,
|
|
53
|
+
}: TLUiSelectProps) {
|
|
54
|
+
const [open, handleOpenChange] = useMenuIsOpen(id, onOpenChange)
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<_Select.Root
|
|
58
|
+
value={value}
|
|
59
|
+
onValueChange={onValueChange}
|
|
60
|
+
onOpenChange={handleOpenChange}
|
|
61
|
+
open={open}
|
|
62
|
+
disabled={disabled}
|
|
63
|
+
dir="ltr"
|
|
64
|
+
>
|
|
65
|
+
<div
|
|
66
|
+
id={id}
|
|
67
|
+
className={classNames('tlui-select', className)}
|
|
68
|
+
data-testid={dataTestId}
|
|
69
|
+
aria-label={ariaLabel}
|
|
70
|
+
>
|
|
71
|
+
{children}
|
|
72
|
+
</div>
|
|
73
|
+
</_Select.Root>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* --------------------- Trigger --------------------- */
|
|
78
|
+
|
|
79
|
+
/** @public */
|
|
80
|
+
export interface TLUiSelectTriggerProps {
|
|
81
|
+
children: React.ReactNode
|
|
82
|
+
className?: string
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The trigger button for the select dropdown.
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
* @react
|
|
90
|
+
*/
|
|
91
|
+
export const TldrawUiSelectTrigger = React.forwardRef<HTMLButtonElement, TLUiSelectTriggerProps>(
|
|
92
|
+
function TldrawUiSelectTrigger({ children, className }, ref) {
|
|
93
|
+
return (
|
|
94
|
+
<_Select.Trigger
|
|
95
|
+
ref={ref}
|
|
96
|
+
className={classNames('tlui-button tlui-select__trigger', className)}
|
|
97
|
+
>
|
|
98
|
+
{children}
|
|
99
|
+
<_Select.Icon className="tlui-select__chevron">
|
|
100
|
+
<TldrawUiIcon icon="chevron-down" label="" small />
|
|
101
|
+
</_Select.Icon>
|
|
102
|
+
</_Select.Trigger>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
/* --------------------- Value --------------------- */
|
|
108
|
+
|
|
109
|
+
/** @public */
|
|
110
|
+
export interface TLUiSelectValueProps {
|
|
111
|
+
placeholder?: string
|
|
112
|
+
icon?: TLUiIconType | Exclude<string, TLUiIconType>
|
|
113
|
+
children?: React.ReactNode
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Displays the currently selected value in the trigger.
|
|
118
|
+
*
|
|
119
|
+
* @public
|
|
120
|
+
* @react
|
|
121
|
+
*/
|
|
122
|
+
export function TldrawUiSelectValue({ placeholder, icon, children }: TLUiSelectValueProps) {
|
|
123
|
+
return (
|
|
124
|
+
<_Select.Value placeholder={placeholder}>
|
|
125
|
+
<span className="tlui-select__value">
|
|
126
|
+
{icon && <TldrawUiIcon icon={icon} label="" small />}
|
|
127
|
+
<span className="tlui-button__label">{children}</span>
|
|
128
|
+
</span>
|
|
129
|
+
</_Select.Value>
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* --------------------- Content --------------------- */
|
|
134
|
+
|
|
135
|
+
/** @public */
|
|
136
|
+
export interface TLUiSelectContentProps {
|
|
137
|
+
children: React.ReactNode
|
|
138
|
+
side?: 'top' | 'bottom'
|
|
139
|
+
align?: 'start' | 'center' | 'end'
|
|
140
|
+
className?: string
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The dropdown content container for select items.
|
|
145
|
+
*
|
|
146
|
+
* @public
|
|
147
|
+
* @react
|
|
148
|
+
*/
|
|
149
|
+
export function TldrawUiSelectContent({
|
|
150
|
+
children,
|
|
151
|
+
side = 'bottom',
|
|
152
|
+
align = 'start',
|
|
153
|
+
className,
|
|
154
|
+
}: TLUiSelectContentProps) {
|
|
155
|
+
const container = useContainer()
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<_Select.Portal container={container}>
|
|
159
|
+
<_Select.Content
|
|
160
|
+
className={classNames('tlui-menu tlui-select__content', className)}
|
|
161
|
+
position="popper"
|
|
162
|
+
side={side}
|
|
163
|
+
align={align}
|
|
164
|
+
sideOffset={4}
|
|
165
|
+
collisionPadding={4}
|
|
166
|
+
>
|
|
167
|
+
<_Select.Viewport className="tlui-select__viewport">{children}</_Select.Viewport>
|
|
168
|
+
</_Select.Content>
|
|
169
|
+
</_Select.Portal>
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* --------------------- Item --------------------- */
|
|
174
|
+
|
|
175
|
+
/** @public */
|
|
176
|
+
export interface TLUiSelectItemProps {
|
|
177
|
+
value: string
|
|
178
|
+
label: string
|
|
179
|
+
icon?: TLUiIconType | Exclude<string, TLUiIconType>
|
|
180
|
+
disabled?: boolean
|
|
181
|
+
className?: string
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* An item in the select dropdown. Styled to match TldrawUiMenuCheckboxItem.
|
|
186
|
+
*
|
|
187
|
+
* @public
|
|
188
|
+
* @react
|
|
189
|
+
*/
|
|
190
|
+
export function TldrawUiSelectItem({
|
|
191
|
+
value,
|
|
192
|
+
label,
|
|
193
|
+
icon,
|
|
194
|
+
disabled,
|
|
195
|
+
className,
|
|
196
|
+
}: TLUiSelectItemProps) {
|
|
197
|
+
return (
|
|
198
|
+
<_Select.Item
|
|
199
|
+
value={value}
|
|
200
|
+
disabled={disabled}
|
|
201
|
+
className={classNames(
|
|
202
|
+
'tlui-button tlui-button__menu tlui-button__checkbox tlui-select__item',
|
|
203
|
+
className
|
|
204
|
+
)}
|
|
205
|
+
>
|
|
206
|
+
<TldrawUiIcon small icon="check" label="" className="tlui-select__item-indicator" />
|
|
207
|
+
{icon && <TldrawUiIcon icon={icon} label="" small />}
|
|
208
|
+
<_Select.ItemText className="tlui-button__label">{label}</_Select.ItemText>
|
|
209
|
+
</_Select.Item>
|
|
210
|
+
)
|
|
211
|
+
}
|
|
@@ -1459,6 +1459,7 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
1459
1459
|
label: 'action.toggle-lock',
|
|
1460
1460
|
kbd: 'shift+l',
|
|
1461
1461
|
onSelect(source) {
|
|
1462
|
+
if (!canApplySelectionAction()) return
|
|
1462
1463
|
editor.markHistoryStoppingPoint('locking')
|
|
1463
1464
|
trackEvent('toggle-lock', { source })
|
|
1464
1465
|
editor.toggleLock(editor.getSelectedShapeIds())
|
|
@@ -1673,6 +1674,7 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
1673
1674
|
label: 'a11y.enlarge-shape',
|
|
1674
1675
|
kbd: 'cmd+alt+shift+=,ctrl+alt+shift+=',
|
|
1675
1676
|
onSelect: async (source) => {
|
|
1677
|
+
if (!canApplySelectionAction()) return
|
|
1676
1678
|
scaleShapes(1.1)
|
|
1677
1679
|
trackEvent('enlarge-shapes', { source })
|
|
1678
1680
|
},
|
|
@@ -1682,6 +1684,7 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
1682
1684
|
label: 'a11y.shrink-shape',
|
|
1683
1685
|
kbd: 'cmd+alt+shift+-,ctrl+alt+shift+-',
|
|
1684
1686
|
onSelect: async (source) => {
|
|
1687
|
+
if (!canApplySelectionAction()) return
|
|
1685
1688
|
scaleShapes(1 / 1.1)
|
|
1686
1689
|
trackEvent('shrink-shapes', { source })
|
|
1687
1690
|
},
|
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 = '4.4.0-canary.
|
|
4
|
+
export const version = '4.4.0-canary.b80d167101d1'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2025-09-18T14:39:22.803Z',
|
|
7
|
-
minor: '2026-02-
|
|
8
|
-
patch: '2026-02-
|
|
7
|
+
minor: '2026-02-09T12:49:21.563Z',
|
|
8
|
+
patch: '2026-02-09T12:49:21.563Z',
|
|
9
9
|
}
|
package/src/lib/ui.css
CHANGED
|
@@ -523,6 +523,52 @@
|
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
+
/* --------------------- Select --------------------- */
|
|
527
|
+
|
|
528
|
+
/* Trigger extends .tlui-button with space-between layout */
|
|
529
|
+
.tlui-select__trigger {
|
|
530
|
+
justify-content: space-between;
|
|
531
|
+
gap: var(--tl-space-3);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
.tlui-select__trigger[data-state='open']::after {
|
|
535
|
+
opacity: 1;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
.tlui-select__value {
|
|
539
|
+
display: flex;
|
|
540
|
+
align-items: center;
|
|
541
|
+
gap: var(--tl-space-2);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
.tlui-select__chevron {
|
|
545
|
+
flex-shrink: 0;
|
|
546
|
+
color: var(--tl-color-text-2);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/* Content extends .tlui-menu with Radix-aware sizing */
|
|
550
|
+
.tlui-select__content {
|
|
551
|
+
min-width: var(--radix-select-trigger-width);
|
|
552
|
+
max-height: var(--radix-select-content-available-height);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
.tlui-select__viewport {
|
|
556
|
+
padding: 4px 0;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/* Item extends .tlui-button__checkbox with left-aligned text */
|
|
560
|
+
.tlui-select__item {
|
|
561
|
+
justify-content: flex-start;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
.tlui-select__item-indicator {
|
|
565
|
+
visibility: hidden;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
.tlui-select__item[data-state='checked'] .tlui-select__item-indicator {
|
|
569
|
+
visibility: visible;
|
|
570
|
+
}
|
|
571
|
+
|
|
526
572
|
/* ----------------------- Kbd ---------------------- */
|
|
527
573
|
|
|
528
574
|
.tlui-kbd {
|
|
@@ -94,7 +94,7 @@ exports[`Matches a snapshot > Basic SVG 1`] = `
|
|
|
94
94
|
xmlns="http://www.w3.org/1999/xhtml"
|
|
95
95
|
>
|
|
96
96
|
<div
|
|
97
|
-
style="font-size: 22px; color: rgb(0, 0, 0); line-height: 1.35; text-align: center; width: 0px; word-wrap: break-word; overflow-wrap: break-word; white-space: pre-wrap; text-shadow: var(--tl-text-outline); position: static; height: 0px; margin: 0px; padding: 0px; border: 0px;"
|
|
97
|
+
style="font-size: 22px; color: rgb(0, 0, 0); line-height: 1.35; text-align: center; width: 0px; word-wrap: break-word; overflow-wrap: break-word; white-space: pre-wrap; text-shadow: var(--tl-text-outline); tab-size: var(--tl-tab-size, 2); position: static; height: 0px; margin: 0px; padding: 0px; border: 0px;"
|
|
98
98
|
>
|
|
99
99
|
<p
|
|
100
100
|
dir="auto"
|
|
@@ -234,7 +234,7 @@ exports[`Returns all shapes when no ids are provided > All shapes 1`] = `
|
|
|
234
234
|
xmlns="http://www.w3.org/1999/xhtml"
|
|
235
235
|
>
|
|
236
236
|
<div
|
|
237
|
-
style="font-size: 22px; color: rgb(0, 0, 0); line-height: 1.35; text-align: center; width: 0px; word-wrap: break-word; overflow-wrap: break-word; white-space: pre-wrap; text-shadow: var(--tl-text-outline); position: static; height: 0px; margin: 0px; padding: 0px; border: 0px;"
|
|
237
|
+
style="font-size: 22px; color: rgb(0, 0, 0); line-height: 1.35; text-align: center; width: 0px; word-wrap: break-word; overflow-wrap: break-word; white-space: pre-wrap; text-shadow: var(--tl-text-outline); tab-size: var(--tl-tab-size, 2); position: static; height: 0px; margin: 0px; padding: 0px; border: 0px;"
|
|
238
238
|
>
|
|
239
239
|
<p
|
|
240
240
|
dir="auto"
|
|
@@ -230,6 +230,115 @@ describe('getDebouncedZoomLevel', () => {
|
|
|
230
230
|
})
|
|
231
231
|
})
|
|
232
232
|
|
|
233
|
+
describe('hover updates during camera movement', () => {
|
|
234
|
+
// Note: These tests verify the hover locking optimization during camera movement.
|
|
235
|
+
// Important: pan({ x, y }) moves the camera, which changes how screen coordinates
|
|
236
|
+
// map to page coordinates. After pan(10, 10), screen point (150, 150) maps to
|
|
237
|
+
// page point (140, 140). Tests account for this by positioning pointer well
|
|
238
|
+
// inside shapes so small pans don't move the effective page point outside.
|
|
239
|
+
|
|
240
|
+
// Note: Default geo shapes have fill: 'none' (hollow), so hit testing only works on edges.
|
|
241
|
+
// For interior points to register hits, shapes must have fill: 'solid'.
|
|
242
|
+
|
|
243
|
+
it('keeps hover when camera starts moving and pointer is over same shape', () => {
|
|
244
|
+
// Create a solid shape so we can hit anywhere inside it
|
|
245
|
+
editor.createShapes([{ type: 'geo', x: 100, y: 100, props: { w: 200, h: 200, fill: 'solid' } }])
|
|
246
|
+
const shape = editor.getLastCreatedShape()
|
|
247
|
+
|
|
248
|
+
// Move pointer to center of shape (200, 200 is center of 100-300 range)
|
|
249
|
+
editor.pointerMove(200, 200)
|
|
250
|
+
expect(editor.getHoveredShapeId()).toBe(shape.id)
|
|
251
|
+
|
|
252
|
+
// Start panning (camera moves)
|
|
253
|
+
// After pan(10,10), screen (200,200) -> page (190,190), still inside shape (100-300)
|
|
254
|
+
editor.pan({ x: 10, y: 10 })
|
|
255
|
+
expect(editor.getCameraState()).toBe('moving')
|
|
256
|
+
|
|
257
|
+
// Trigger a pointer move at the same screen position
|
|
258
|
+
// Page point is (190, 190) which is still inside the shape
|
|
259
|
+
editor.pointerMove(200, 200)
|
|
260
|
+
expect(editor.getHoveredShapeId()).toBe(shape.id)
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
it('clears and locks hover when pointer moves to empty area while camera is moving', () => {
|
|
264
|
+
// Create a solid shape so we can hit anywhere inside it
|
|
265
|
+
editor.createShapes([{ type: 'geo', x: 100, y: 100, props: { w: 200, h: 200, fill: 'solid' } }])
|
|
266
|
+
const shape = editor.getLastCreatedShape()
|
|
267
|
+
|
|
268
|
+
// Move pointer over shape to hover it
|
|
269
|
+
editor.pointerMove(200, 200)
|
|
270
|
+
expect(editor.getHoveredShapeId()).toBe(shape.id)
|
|
271
|
+
|
|
272
|
+
// Start panning
|
|
273
|
+
editor.pan({ x: 10, y: 10 })
|
|
274
|
+
expect(editor.getCameraState()).toBe('moving')
|
|
275
|
+
|
|
276
|
+
// Move pointer to empty area - hover changes to null, so it locks
|
|
277
|
+
editor.pointerMove(500, 500)
|
|
278
|
+
expect(editor.getHoveredShapeId()).toBe(null)
|
|
279
|
+
|
|
280
|
+
// Move pointer back to shape while still moving - should stay locked (no hover)
|
|
281
|
+
editor.pointerMove(200, 200)
|
|
282
|
+
expect(editor.getHoveredShapeId()).toBe(null)
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
it('resumes hover updates when camera becomes idle', () => {
|
|
286
|
+
// Create a solid shape so we can hit anywhere inside it
|
|
287
|
+
editor.createShapes([{ type: 'geo', x: 100, y: 100, props: { w: 200, h: 200, fill: 'solid' } }])
|
|
288
|
+
const shape = editor.getLastCreatedShape()
|
|
289
|
+
|
|
290
|
+
// Move pointer over shape
|
|
291
|
+
editor.pointerMove(200, 200)
|
|
292
|
+
expect(editor.getHoveredShapeId()).toBe(shape.id)
|
|
293
|
+
|
|
294
|
+
// Start panning and move pointer off shape to trigger lock
|
|
295
|
+
editor.pan({ x: 10, y: 10 })
|
|
296
|
+
expect(editor.getCameraState()).toBe('moving')
|
|
297
|
+
editor.pointerMove(500, 500) // Move to empty area
|
|
298
|
+
expect(editor.getHoveredShapeId()).toBe(null)
|
|
299
|
+
|
|
300
|
+
// Move pointer back over shape while still moving - still locked
|
|
301
|
+
editor.pointerMove(200, 200)
|
|
302
|
+
expect(editor.getHoveredShapeId()).toBe(null)
|
|
303
|
+
|
|
304
|
+
// Let camera settle
|
|
305
|
+
editor.forceTick(5)
|
|
306
|
+
expect(editor.getCameraState()).toBe('idle')
|
|
307
|
+
|
|
308
|
+
// Move pointer again now that camera is idle - hover should update
|
|
309
|
+
// After pan(10,10), screen (200,200) -> page (190,190), still inside shape
|
|
310
|
+
editor.pointerMove(200, 200)
|
|
311
|
+
expect(editor.getHoveredShapeId()).toBe(shape.id)
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
it('locks immediately if there is no current hover when camera starts moving', () => {
|
|
315
|
+
// Create a solid shape so we can hit anywhere inside it
|
|
316
|
+
editor.createShapes([{ type: 'geo', x: 100, y: 100, props: { w: 200, h: 200, fill: 'solid' } }])
|
|
317
|
+
const shape = editor.getLastCreatedShape()
|
|
318
|
+
|
|
319
|
+
// Pointer is not over any shape
|
|
320
|
+
editor.pointerMove(500, 500)
|
|
321
|
+
expect(editor.getHoveredShapeId()).toBe(null)
|
|
322
|
+
|
|
323
|
+
// Start panning
|
|
324
|
+
editor.pan({ x: 10, y: 10 })
|
|
325
|
+
expect(editor.getCameraState()).toBe('moving')
|
|
326
|
+
|
|
327
|
+
// Move pointer over shape while moving - should be locked since no previous hover
|
|
328
|
+
editor.pointerMove(200, 200)
|
|
329
|
+
expect(editor.getHoveredShapeId()).toBe(null)
|
|
330
|
+
|
|
331
|
+
// Let camera settle
|
|
332
|
+
editor.forceTick(5)
|
|
333
|
+
expect(editor.getCameraState()).toBe('idle')
|
|
334
|
+
|
|
335
|
+
// Move pointer again now that camera is idle - hover should work
|
|
336
|
+
// After pan(10,10), screen (200,200) -> page (190,190), still inside shape
|
|
337
|
+
editor.pointerMove(200, 200)
|
|
338
|
+
expect(editor.getHoveredShapeId()).toBe(shape.id)
|
|
339
|
+
})
|
|
340
|
+
})
|
|
341
|
+
|
|
233
342
|
describe('getEfficientZoomLevel', () => {
|
|
234
343
|
it('returns current zoom level when below shape threshold', () => {
|
|
235
344
|
// Default threshold is 500 shapes, we have 0
|
package/tldraw.css
CHANGED
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
|
|
65
65
|
/* Misc */
|
|
66
66
|
--tl-zoom: 1;
|
|
67
|
+
--tl-tab-size: 2;
|
|
67
68
|
|
|
68
69
|
/* Cursor SVGs */
|
|
69
70
|
--tl-cursor-none: none;
|
|
@@ -899,6 +900,10 @@ input,
|
|
|
899
900
|
/* white-space: break-spaces; */
|
|
900
901
|
}
|
|
901
902
|
|
|
903
|
+
.tl-rich-text {
|
|
904
|
+
tab-size: var(--tl-tab-size, 2);
|
|
905
|
+
}
|
|
906
|
+
|
|
902
907
|
.tl-rich-text p {
|
|
903
908
|
margin: 0;
|
|
904
909
|
/* Depending on the extensions, <p> tags can be empty, without a <br />. */
|
|
@@ -2323,6 +2328,52 @@ it from receiving any pointer events or affecting the cursor. */
|
|
|
2323
2328
|
}
|
|
2324
2329
|
}
|
|
2325
2330
|
|
|
2331
|
+
/* --------------------- Select --------------------- */
|
|
2332
|
+
|
|
2333
|
+
/* Trigger extends .tlui-button with space-between layout */
|
|
2334
|
+
.tlui-select__trigger {
|
|
2335
|
+
justify-content: space-between;
|
|
2336
|
+
gap: var(--tl-space-3);
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
.tlui-select__trigger[data-state='open']::after {
|
|
2340
|
+
opacity: 1;
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
.tlui-select__value {
|
|
2344
|
+
display: flex;
|
|
2345
|
+
align-items: center;
|
|
2346
|
+
gap: var(--tl-space-2);
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
.tlui-select__chevron {
|
|
2350
|
+
flex-shrink: 0;
|
|
2351
|
+
color: var(--tl-color-text-2);
|
|
2352
|
+
}
|
|
2353
|
+
|
|
2354
|
+
/* Content extends .tlui-menu with Radix-aware sizing */
|
|
2355
|
+
.tlui-select__content {
|
|
2356
|
+
min-width: var(--radix-select-trigger-width);
|
|
2357
|
+
max-height: var(--radix-select-content-available-height);
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
.tlui-select__viewport {
|
|
2361
|
+
padding: 4px 0;
|
|
2362
|
+
}
|
|
2363
|
+
|
|
2364
|
+
/* Item extends .tlui-button__checkbox with left-aligned text */
|
|
2365
|
+
.tlui-select__item {
|
|
2366
|
+
justify-content: flex-start;
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
.tlui-select__item-indicator {
|
|
2370
|
+
visibility: hidden;
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2373
|
+
.tlui-select__item[data-state='checked'] .tlui-select__item-indicator {
|
|
2374
|
+
visibility: visible;
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2326
2377
|
/* ----------------------- Kbd ---------------------- */
|
|
2327
2378
|
|
|
2328
2379
|
.tlui-kbd {
|