tldraw 3.16.0-canary.39bd199a7aa6 → 3.16.0-canary.5dac57cf9465
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 +57 -3
- package/dist-cjs/index.js +10 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/usePrefersReducedMotion.js +10 -1
- package/dist-cjs/lib/shapes/shared/usePrefersReducedMotion.js.map +2 -2
- package/dist-cjs/lib/ui/components/AccessibilityMenu.js +35 -0
- package/dist-cjs/lib/ui/components/AccessibilityMenu.js.map +7 -0
- package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js +2 -1
- package/dist-cjs/lib/ui/components/ActionsMenu/DefaultActionsMenu.js.map +2 -2
- package/dist-cjs/lib/ui/components/DefaultMenuPanel.js +3 -2
- package/dist-cjs/lib/ui/components/DefaultMenuPanel.js.map +2 -2
- package/dist-cjs/lib/ui/components/MainMenu/DefaultMainMenuContent.js +3 -3
- package/dist-cjs/lib/ui/components/MainMenu/DefaultMainMenuContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/NavigationPanel/DefaultNavigationPanel.js +1 -1
- package/dist-cjs/lib/ui/components/NavigationPanel/DefaultNavigationPanel.js.map +2 -2
- package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js +2 -1
- package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js.map +2 -2
- package/dist-cjs/lib/ui/components/SharePanel/PeopleMenuItem.js +3 -2
- package/dist-cjs/lib/ui/components/SharePanel/PeopleMenuItem.js.map +2 -2
- package/dist-cjs/lib/ui/components/SharePanel/UserPresenceColorPicker.js +2 -2
- package/dist-cjs/lib/ui/components/SharePanel/UserPresenceColorPicker.js.map +2 -2
- package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanel.js +2 -0
- package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanel.js.map +2 -2
- package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js +171 -140
- package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/StylePanel/DoubleDropdownPicker.js +3 -3
- package/dist-cjs/lib/ui/components/StylePanel/DoubleDropdownPicker.js.map +2 -2
- package/dist-cjs/lib/ui/components/StylePanel/DropdownPicker.js +26 -25
- package/dist-cjs/lib/ui/components/StylePanel/DropdownPicker.js.map +3 -3
- package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js +6 -5
- package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js.map +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js +9 -10
- package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js.map +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js +5 -4
- package/dist-cjs/lib/ui/components/Toolbar/ToggleToolLockedButton.js.map +2 -2
- package/dist-cjs/lib/ui/components/menu-items.js +6 -0
- package/dist-cjs/lib/ui/components/menu-items.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js +4 -15
- package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js.map +3 -3
- package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js +1 -1
- package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiPopover.js +3 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiPopover.js.map +3 -3
- package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js +18 -7
- package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +267 -0
- package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js.map +7 -0
- package/dist-cjs/lib/ui/components/primitives/layout.js +51 -0
- package/dist-cjs/lib/ui/components/primitives/layout.js.map +7 -0
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js +0 -1
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js.map +2 -2
- package/dist-cjs/lib/ui/context/TldrawUiContextProvider.js +3 -2
- package/dist-cjs/lib/ui/context/TldrawUiContextProvider.js.map +2 -2
- package/dist-cjs/lib/ui/context/actions.js +15 -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/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
- package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +3 -0
- package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.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 +57 -3
- package/dist-esm/index.mjs +17 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/usePrefersReducedMotion.mjs +10 -1
- package/dist-esm/lib/shapes/shared/usePrefersReducedMotion.mjs.map +2 -2
- package/dist-esm/lib/ui/components/AccessibilityMenu.mjs +19 -0
- package/dist-esm/lib/ui/components/AccessibilityMenu.mjs.map +7 -0
- package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs +2 -1
- package/dist-esm/lib/ui/components/ActionsMenu/DefaultActionsMenu.mjs.map +2 -2
- package/dist-esm/lib/ui/components/DefaultMenuPanel.mjs +3 -2
- package/dist-esm/lib/ui/components/DefaultMenuPanel.mjs.map +2 -2
- package/dist-esm/lib/ui/components/MainMenu/DefaultMainMenuContent.mjs +3 -5
- package/dist-esm/lib/ui/components/MainMenu/DefaultMainMenuContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/NavigationPanel/DefaultNavigationPanel.mjs +1 -1
- package/dist-esm/lib/ui/components/NavigationPanel/DefaultNavigationPanel.mjs.map +2 -2
- package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs +2 -1
- package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs.map +2 -2
- package/dist-esm/lib/ui/components/SharePanel/PeopleMenuItem.mjs +3 -2
- package/dist-esm/lib/ui/components/SharePanel/PeopleMenuItem.mjs.map +2 -2
- package/dist-esm/lib/ui/components/SharePanel/UserPresenceColorPicker.mjs +2 -2
- package/dist-esm/lib/ui/components/SharePanel/UserPresenceColorPicker.mjs.map +2 -2
- package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanel.mjs +3 -1
- package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanel.mjs.map +2 -2
- package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs +171 -140
- package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/StylePanel/DoubleDropdownPicker.mjs +3 -3
- package/dist-esm/lib/ui/components/StylePanel/DoubleDropdownPicker.mjs.map +2 -2
- package/dist-esm/lib/ui/components/StylePanel/DropdownPicker.mjs +26 -25
- package/dist-esm/lib/ui/components/StylePanel/DropdownPicker.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs +6 -5
- package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs +9 -10
- package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs +5 -4
- package/dist-esm/lib/ui/components/Toolbar/ToggleToolLockedButton.mjs.map +2 -2
- package/dist-esm/lib/ui/components/menu-items.mjs +6 -0
- package/dist-esm/lib/ui/components/menu-items.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs +4 -5
- package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs +1 -1
- package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiPopover.mjs +3 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiPopover.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs +18 -7
- package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs +237 -0
- package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs.map +7 -0
- package/dist-esm/lib/ui/components/primitives/layout.mjs +21 -0
- package/dist-esm/lib/ui/components/primitives/layout.mjs.map +7 -0
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs +0 -1
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs.map +2 -2
- package/dist-esm/lib/ui/context/TldrawUiContextProvider.mjs +3 -2
- package/dist-esm/lib/ui/context/TldrawUiContextProvider.mjs.map +2 -2
- package/dist-esm/lib/ui/context/actions.mjs +15 -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/hooks/useTranslation/defaultTranslation.mjs +3 -0
- package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.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 +13 -0
- package/src/lib/shapes/shared/usePrefersReducedMotion.tsx +11 -1
- package/src/lib/ui/components/AccessibilityMenu.tsx +20 -0
- package/src/lib/ui/components/ActionsMenu/DefaultActionsMenu.tsx +2 -1
- package/src/lib/ui/components/DefaultMenuPanel.tsx +4 -3
- package/src/lib/ui/components/MainMenu/DefaultMainMenuContent.tsx +4 -4
- package/src/lib/ui/components/NavigationPanel/DefaultNavigationPanel.tsx +1 -1
- package/src/lib/ui/components/PageMenu/DefaultPageMenu.tsx +3 -2
- package/src/lib/ui/components/SharePanel/PeopleMenuItem.tsx +4 -3
- package/src/lib/ui/components/SharePanel/UserPresenceColorPicker.tsx +3 -3
- package/src/lib/ui/components/StylePanel/DefaultStylePanel.tsx +3 -1
- package/src/lib/ui/components/StylePanel/DefaultStylePanelContent.tsx +146 -107
- package/src/lib/ui/components/StylePanel/DoubleDropdownPicker.tsx +3 -3
- package/src/lib/ui/components/StylePanel/DropdownPicker.tsx +7 -6
- package/src/lib/ui/components/Toolbar/DefaultToolbar.tsx +7 -6
- package/src/lib/ui/components/Toolbar/OverflowingToolbar.tsx +10 -11
- package/src/lib/ui/components/Toolbar/ToggleToolLockedButton.tsx +14 -11
- package/src/lib/ui/components/menu-items.tsx +8 -0
- package/src/lib/ui/components/primitives/TldrawUiButtonPicker.tsx +38 -36
- package/src/lib/ui/components/primitives/TldrawUiContextualToolbar.tsx +1 -1
- package/src/lib/ui/components/primitives/TldrawUiPopover.tsx +4 -2
- package/src/lib/ui/components/primitives/TldrawUiToolbar.tsx +34 -12
- package/src/lib/ui/components/primitives/TldrawUiTooltip.tsx +313 -0
- package/src/lib/ui/components/primitives/layout.tsx +33 -0
- package/src/lib/ui/components/primitives/menus/TldrawUiMenuItem.tsx +0 -1
- package/src/lib/ui/context/TldrawUiContextProvider.tsx +23 -20
- package/src/lib/ui/context/actions.tsx +15 -0
- package/src/lib/ui/context/events.tsx +1 -0
- package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +3 -0
- package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +3 -0
- package/src/lib/ui/version.ts +3 -3
- package/src/lib/ui.css +80 -69
- package/tldraw.css +82 -69
|
@@ -172,7 +172,7 @@ export const TldrawUiContextualToolbar = ({
|
|
|
172
172
|
className={classNames('tlui-contextual-toolbar', className)}
|
|
173
173
|
onPointerDown={stopEventPropagation}
|
|
174
174
|
>
|
|
175
|
-
<TldrawUiToolbar className="tlui-menu
|
|
175
|
+
<TldrawUiToolbar orientation="horizontal" className="tlui-menu" label={label}>
|
|
176
176
|
{children}
|
|
177
177
|
</TldrawUiToolbar>
|
|
178
178
|
</div>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useContainer } from '@tldraw/editor'
|
|
2
|
+
import classNames from 'classnames'
|
|
2
3
|
import { Popover as _Popover } from 'radix-ui'
|
|
3
4
|
import React from 'react'
|
|
4
5
|
import { useMenuIsOpen } from '../../hooks/useMenuIsOpen'
|
|
@@ -9,15 +10,16 @@ export interface TLUiPopoverProps {
|
|
|
9
10
|
open?: boolean
|
|
10
11
|
children: React.ReactNode
|
|
11
12
|
onOpenChange?(isOpen: boolean): void
|
|
13
|
+
className?: string
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
/** @public @react */
|
|
15
|
-
export function TldrawUiPopover({ id, children, onOpenChange, open }: TLUiPopoverProps) {
|
|
17
|
+
export function TldrawUiPopover({ id, children, onOpenChange, open, className }: TLUiPopoverProps) {
|
|
16
18
|
const [isOpen, handleOpenChange] = useMenuIsOpen(id, onOpenChange)
|
|
17
19
|
|
|
18
20
|
return (
|
|
19
21
|
<_Popover.Root onOpenChange={handleOpenChange} open={open || isOpen /* allow debugging */}>
|
|
20
|
-
<div className=
|
|
22
|
+
<div className={classNames('tlui-popover', className)}>{children}</div>
|
|
21
23
|
</_Popover.Root>
|
|
22
24
|
)
|
|
23
25
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import classnames from 'classnames'
|
|
2
2
|
import { Toolbar as _Toolbar } from 'radix-ui'
|
|
3
3
|
import React from 'react'
|
|
4
|
+
import { TldrawUiGrid, TldrawUiRow } from './layout'
|
|
5
|
+
import { TldrawUiTooltip } from './TldrawUiTooltip'
|
|
4
6
|
|
|
5
7
|
/** @public */
|
|
6
8
|
export interface TLUiToolbarProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
@@ -8,20 +10,25 @@ export interface TLUiToolbarProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
8
10
|
className?: string
|
|
9
11
|
dir?: 'ltr' | 'rtl'
|
|
10
12
|
label: string
|
|
13
|
+
orientation?: 'horizontal' | 'grid'
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
/** @public @react */
|
|
14
17
|
export const TldrawUiToolbar = React.forwardRef<HTMLDivElement, TLUiToolbarProps>(
|
|
15
|
-
({ children, className, label, ...props }: TLUiToolbarProps, ref) => {
|
|
18
|
+
({ children, className, label, orientation = 'horizontal', ...props }: TLUiToolbarProps, ref) => {
|
|
19
|
+
const Layout = orientation === 'grid' ? TldrawUiGrid : TldrawUiRow
|
|
16
20
|
return (
|
|
17
|
-
<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
<Layout asChild>
|
|
22
|
+
<_Toolbar.Root
|
|
23
|
+
ref={ref}
|
|
24
|
+
{...props}
|
|
25
|
+
className={classnames('tlui-toolbar', className)}
|
|
26
|
+
aria-label={label}
|
|
27
|
+
orientation={orientation === 'grid' ? 'horizontal' : orientation}
|
|
28
|
+
>
|
|
29
|
+
{children}
|
|
30
|
+
</_Toolbar.Root>
|
|
31
|
+
</Layout>
|
|
25
32
|
)
|
|
26
33
|
}
|
|
27
34
|
)
|
|
@@ -34,23 +41,30 @@ export interface TLUiToolbarButtonProps extends React.HTMLAttributes<HTMLButtonE
|
|
|
34
41
|
disabled?: boolean
|
|
35
42
|
isActive?: boolean
|
|
36
43
|
type: 'icon' | 'tool' | 'menu'
|
|
44
|
+
tooltip?: string
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
/** @public @react */
|
|
40
48
|
export const TldrawUiToolbarButton = React.forwardRef<HTMLButtonElement, TLUiToolbarButtonProps>(
|
|
41
|
-
({ asChild, children, type, isActive, ...props }: TLUiToolbarButtonProps, ref) => {
|
|
42
|
-
|
|
49
|
+
({ asChild, children, type, isActive, tooltip, ...props }: TLUiToolbarButtonProps, ref) => {
|
|
50
|
+
const button = (
|
|
43
51
|
<_Toolbar.Button
|
|
44
52
|
ref={ref}
|
|
45
53
|
asChild={asChild}
|
|
46
54
|
draggable={false}
|
|
47
55
|
data-isactive={isActive}
|
|
48
56
|
{...props}
|
|
57
|
+
// The tooltip takes care of this.
|
|
58
|
+
title={undefined}
|
|
49
59
|
className={classnames('tlui-button', `tlui-button__${type}`, props.className)}
|
|
50
60
|
>
|
|
51
61
|
{children}
|
|
52
62
|
</_Toolbar.Button>
|
|
53
63
|
)
|
|
64
|
+
|
|
65
|
+
const tooltipContent = tooltip || props.title
|
|
66
|
+
|
|
67
|
+
return <TldrawUiTooltip content={tooltipContent}>{button}</TldrawUiTooltip>
|
|
54
68
|
}
|
|
55
69
|
)
|
|
56
70
|
|
|
@@ -93,6 +107,7 @@ export interface TLUiToolbarToggleItemProps extends React.HTMLAttributes<HTMLBut
|
|
|
93
107
|
className?: string
|
|
94
108
|
type: 'icon' | 'tool'
|
|
95
109
|
value: string
|
|
110
|
+
tooltip?: string
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
/** @public @react */
|
|
@@ -101,11 +116,14 @@ export const TldrawUiToolbarToggleItem = ({
|
|
|
101
116
|
className,
|
|
102
117
|
type,
|
|
103
118
|
value,
|
|
119
|
+
tooltip,
|
|
104
120
|
...props
|
|
105
121
|
}: TLUiToolbarToggleItemProps) => {
|
|
106
|
-
|
|
122
|
+
const toggleItem = (
|
|
107
123
|
<_Toolbar.ToggleItem
|
|
108
124
|
{...props}
|
|
125
|
+
// The tooltip takes care of this.
|
|
126
|
+
title={undefined}
|
|
109
127
|
className={classnames(
|
|
110
128
|
'tlui-button',
|
|
111
129
|
`tlui-button__${type}`,
|
|
@@ -117,4 +135,8 @@ export const TldrawUiToolbarToggleItem = ({
|
|
|
117
135
|
{children}
|
|
118
136
|
</_Toolbar.ToggleItem>
|
|
119
137
|
)
|
|
138
|
+
|
|
139
|
+
const tooltipContent = tooltip || props.title
|
|
140
|
+
|
|
141
|
+
return <TldrawUiTooltip content={tooltipContent}>{toggleItem}</TldrawUiTooltip>
|
|
120
142
|
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { Editor, uniqueId, useMaybeEditor, Vec } from '@tldraw/editor'
|
|
2
|
+
import { Tooltip as _Tooltip } from 'radix-ui'
|
|
3
|
+
import React, { createContext, useContext, useEffect, useRef, useState } from 'react'
|
|
4
|
+
import { usePrefersReducedMotion } from '../../../shapes/shared/usePrefersReducedMotion'
|
|
5
|
+
|
|
6
|
+
const DEFAULT_TOOLTIP_DELAY_MS = 700
|
|
7
|
+
|
|
8
|
+
/** @public */
|
|
9
|
+
export interface TldrawUiTooltipProps {
|
|
10
|
+
children: React.ReactNode
|
|
11
|
+
content?: string | React.ReactNode
|
|
12
|
+
side?: 'top' | 'right' | 'bottom' | 'left'
|
|
13
|
+
sideOffset?: number
|
|
14
|
+
disabled?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Singleton tooltip manager
|
|
18
|
+
class TooltipManager {
|
|
19
|
+
private static instance: TooltipManager | null = null
|
|
20
|
+
private currentTooltipId: string | null = null
|
|
21
|
+
private currentContent: string | React.ReactNode = ''
|
|
22
|
+
private currentSide: 'top' | 'right' | 'bottom' | 'left' = 'bottom'
|
|
23
|
+
private currentSideOffset: number = 5
|
|
24
|
+
private destroyTimeoutId: number | null = null
|
|
25
|
+
private subscribers: Set<() => void> = new Set()
|
|
26
|
+
private activeElement: HTMLElement | null = null
|
|
27
|
+
private editor: Editor | null = null
|
|
28
|
+
|
|
29
|
+
static getInstance(): TooltipManager {
|
|
30
|
+
if (!TooltipManager.instance) {
|
|
31
|
+
TooltipManager.instance = new TooltipManager()
|
|
32
|
+
}
|
|
33
|
+
return TooltipManager.instance
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setEditor(editor: Editor | null) {
|
|
37
|
+
this.editor = editor
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
subscribe(callback: () => void): () => void {
|
|
41
|
+
this.subscribers.add(callback)
|
|
42
|
+
return () => this.subscribers.delete(callback)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private notify() {
|
|
46
|
+
this.subscribers.forEach((callback) => callback())
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
showTooltip(
|
|
50
|
+
tooltipId: string,
|
|
51
|
+
content: string | React.ReactNode,
|
|
52
|
+
element: HTMLElement,
|
|
53
|
+
side: 'top' | 'right' | 'bottom' | 'left' = 'bottom',
|
|
54
|
+
sideOffset: number = 5
|
|
55
|
+
) {
|
|
56
|
+
// Clear any existing destroy timeout
|
|
57
|
+
if (this.destroyTimeoutId) {
|
|
58
|
+
clearTimeout(this.destroyTimeoutId)
|
|
59
|
+
this.destroyTimeoutId = null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Update current tooltip
|
|
63
|
+
this.currentTooltipId = tooltipId
|
|
64
|
+
this.currentContent = content
|
|
65
|
+
this.currentSide = side
|
|
66
|
+
this.currentSideOffset = sideOffset
|
|
67
|
+
this.activeElement = element
|
|
68
|
+
|
|
69
|
+
this.notify()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
hideTooltip(tooltipId: string) {
|
|
73
|
+
// Only hide if this is the current tooltip
|
|
74
|
+
if (this.currentTooltipId === tooltipId) {
|
|
75
|
+
// Start destroy timeout (1 second)
|
|
76
|
+
if (this.editor) {
|
|
77
|
+
this.destroyTimeoutId = this.editor.timers.setTimeout(() => {
|
|
78
|
+
this.currentTooltipId = null
|
|
79
|
+
this.currentContent = ''
|
|
80
|
+
this.activeElement = null
|
|
81
|
+
this.destroyTimeoutId = null
|
|
82
|
+
this.notify()
|
|
83
|
+
}, 300)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getCurrentTooltipData() {
|
|
89
|
+
return {
|
|
90
|
+
id: this.currentTooltipId,
|
|
91
|
+
content: this.currentContent,
|
|
92
|
+
side: this.currentSide,
|
|
93
|
+
sideOffset: this.currentSideOffset,
|
|
94
|
+
element: this.activeElement,
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const tooltipManager = TooltipManager.getInstance()
|
|
100
|
+
|
|
101
|
+
// Context for the tooltip singleton
|
|
102
|
+
const TooltipSingletonContext = createContext<boolean>(false)
|
|
103
|
+
|
|
104
|
+
/** @public */
|
|
105
|
+
export interface TldrawUiTooltipProviderProps {
|
|
106
|
+
children: React.ReactNode
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** @public @react */
|
|
110
|
+
export function TldrawUiTooltipProvider({ children }: TldrawUiTooltipProviderProps) {
|
|
111
|
+
return (
|
|
112
|
+
<_Tooltip.Provider skipDelayDuration={700}>
|
|
113
|
+
<TooltipSingletonContext.Provider value={true}>
|
|
114
|
+
{children}
|
|
115
|
+
<TooltipSingleton />
|
|
116
|
+
</TooltipSingletonContext.Provider>
|
|
117
|
+
</_Tooltip.Provider>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// The singleton tooltip component that renders once
|
|
122
|
+
function TooltipSingleton() {
|
|
123
|
+
const editor = useMaybeEditor()
|
|
124
|
+
const [, forceUpdate] = useState({})
|
|
125
|
+
const [isOpen, setIsOpen] = useState(false)
|
|
126
|
+
const triggerRef = useRef<HTMLDivElement>(null)
|
|
127
|
+
const previousPositionRef = useRef<{ x: number; y: number } | null>(null)
|
|
128
|
+
const prefersReducedMotion = usePrefersReducedMotion()
|
|
129
|
+
const [shouldAnimate, setShouldAnimate] = useState(false)
|
|
130
|
+
const isFirstShowRef = useRef(true)
|
|
131
|
+
const showTimeoutRef = useRef<number | null>(null)
|
|
132
|
+
|
|
133
|
+
// Set editor in tooltip manager
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
tooltipManager.setEditor(editor)
|
|
136
|
+
}, [editor])
|
|
137
|
+
|
|
138
|
+
// Subscribe to tooltip manager updates
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
const unsubscribe = tooltipManager.subscribe(() => {
|
|
141
|
+
forceUpdate({})
|
|
142
|
+
})
|
|
143
|
+
return unsubscribe
|
|
144
|
+
}, [])
|
|
145
|
+
|
|
146
|
+
const tooltipData = tooltipManager.getCurrentTooltipData()
|
|
147
|
+
|
|
148
|
+
// Update open state and trigger position
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
const shouldBeOpen = Boolean(tooltipData.id && tooltipData.element)
|
|
151
|
+
|
|
152
|
+
// Clear any existing show timeout
|
|
153
|
+
if (showTimeoutRef.current) {
|
|
154
|
+
clearTimeout(showTimeoutRef.current)
|
|
155
|
+
showTimeoutRef.current = null
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (shouldBeOpen && tooltipData.element && triggerRef.current) {
|
|
159
|
+
// Position the invisible trigger element over the active element
|
|
160
|
+
const activeRect = tooltipData.element.getBoundingClientRect()
|
|
161
|
+
const trigger = triggerRef.current
|
|
162
|
+
|
|
163
|
+
const newPosition = {
|
|
164
|
+
x: activeRect.left + activeRect.width / 2,
|
|
165
|
+
y: activeRect.top + activeRect.height / 2,
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Determine if we should animate
|
|
169
|
+
let shouldAnimateCheck = false
|
|
170
|
+
if (previousPositionRef.current) {
|
|
171
|
+
const isNearPrevious = Vec.DistMin(previousPositionRef.current, newPosition, 200)
|
|
172
|
+
// Only animate if the distance is less than 200px (nearby tooltips)
|
|
173
|
+
shouldAnimateCheck =
|
|
174
|
+
!prefersReducedMotion &&
|
|
175
|
+
isNearPrevious &&
|
|
176
|
+
Math.abs(newPosition.y - previousPositionRef.current.y) < 50
|
|
177
|
+
}
|
|
178
|
+
// Don't animate on initial show (previousPositionRef.current is null)
|
|
179
|
+
|
|
180
|
+
setShouldAnimate(isFirstShowRef.current ? false : shouldAnimateCheck)
|
|
181
|
+
previousPositionRef.current = newPosition
|
|
182
|
+
|
|
183
|
+
trigger.style.position = 'fixed'
|
|
184
|
+
trigger.style.left = `${activeRect.left}px`
|
|
185
|
+
trigger.style.top = `${activeRect.top}px`
|
|
186
|
+
trigger.style.width = `${activeRect.width}px`
|
|
187
|
+
trigger.style.height = `${activeRect.height}px`
|
|
188
|
+
trigger.style.pointerEvents = 'none'
|
|
189
|
+
trigger.style.zIndex = '9999'
|
|
190
|
+
|
|
191
|
+
// Handle delay for first show
|
|
192
|
+
if (isFirstShowRef.current && editor) {
|
|
193
|
+
showTimeoutRef.current = editor.timers.setTimeout(() => {
|
|
194
|
+
setIsOpen(true)
|
|
195
|
+
isFirstShowRef.current = false
|
|
196
|
+
}, editor.options.tooltipDelayMs)
|
|
197
|
+
} else {
|
|
198
|
+
// Subsequent tooltips show immediately
|
|
199
|
+
setIsOpen(true)
|
|
200
|
+
}
|
|
201
|
+
} else if (!shouldBeOpen) {
|
|
202
|
+
// Hide tooltip immediately
|
|
203
|
+
setIsOpen(false)
|
|
204
|
+
// Reset position tracking when tooltip closes
|
|
205
|
+
previousPositionRef.current = null
|
|
206
|
+
setShouldAnimate(false)
|
|
207
|
+
// Reset first show state after tooltip is hidden
|
|
208
|
+
isFirstShowRef.current = true
|
|
209
|
+
}
|
|
210
|
+
}, [tooltipData.id, tooltipData.element, editor, prefersReducedMotion])
|
|
211
|
+
|
|
212
|
+
if (!tooltipData.id) {
|
|
213
|
+
return null
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<_Tooltip.Root open={isOpen} delayDuration={0}>
|
|
218
|
+
<_Tooltip.Trigger asChild>
|
|
219
|
+
<div ref={triggerRef} />
|
|
220
|
+
</_Tooltip.Trigger>
|
|
221
|
+
<_Tooltip.Content
|
|
222
|
+
className="tlui-tooltip"
|
|
223
|
+
data-should-animate={shouldAnimate}
|
|
224
|
+
side={tooltipData.side}
|
|
225
|
+
sideOffset={tooltipData.sideOffset}
|
|
226
|
+
avoidCollisions
|
|
227
|
+
collisionPadding={8}
|
|
228
|
+
dir="ltr"
|
|
229
|
+
>
|
|
230
|
+
{tooltipData.content}
|
|
231
|
+
<_Tooltip.Arrow className="tlui-tooltip__arrow" />
|
|
232
|
+
</_Tooltip.Content>
|
|
233
|
+
</_Tooltip.Root>
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** @public @react */
|
|
238
|
+
export function TldrawUiTooltip({
|
|
239
|
+
children,
|
|
240
|
+
content,
|
|
241
|
+
side = 'bottom',
|
|
242
|
+
sideOffset = 5,
|
|
243
|
+
disabled = false,
|
|
244
|
+
}: TldrawUiTooltipProps) {
|
|
245
|
+
const editor = useMaybeEditor()
|
|
246
|
+
const tooltipId = useRef<string>(uniqueId())
|
|
247
|
+
const hasProvider = useContext(TooltipSingletonContext)
|
|
248
|
+
|
|
249
|
+
// Don't show tooltip if disabled, no content, or UI labels are disabled
|
|
250
|
+
if (disabled || !content) {
|
|
251
|
+
return <>{children}</>
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Fallback to old behavior if no provider
|
|
255
|
+
if (!hasProvider) {
|
|
256
|
+
return (
|
|
257
|
+
<_Tooltip.Root
|
|
258
|
+
delayDuration={editor?.options.tooltipDelayMs || DEFAULT_TOOLTIP_DELAY_MS}
|
|
259
|
+
disableHoverableContent
|
|
260
|
+
>
|
|
261
|
+
<_Tooltip.Trigger asChild>{children}</_Tooltip.Trigger>
|
|
262
|
+
<_Tooltip.Content
|
|
263
|
+
className="tlui-tooltip"
|
|
264
|
+
side={side}
|
|
265
|
+
sideOffset={sideOffset}
|
|
266
|
+
avoidCollisions
|
|
267
|
+
collisionPadding={8}
|
|
268
|
+
dir="ltr"
|
|
269
|
+
>
|
|
270
|
+
{content}
|
|
271
|
+
<_Tooltip.Arrow className="tlui-tooltip__arrow" />
|
|
272
|
+
</_Tooltip.Content>
|
|
273
|
+
</_Tooltip.Root>
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const handleMouseEnter = (event: React.MouseEvent<HTMLElement>) => {
|
|
278
|
+
tooltipManager.showTooltip(
|
|
279
|
+
tooltipId.current,
|
|
280
|
+
content,
|
|
281
|
+
event.currentTarget as HTMLElement,
|
|
282
|
+
side,
|
|
283
|
+
sideOffset
|
|
284
|
+
)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const handleMouseLeave = () => {
|
|
288
|
+
tooltipManager.hideTooltip(tooltipId.current)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const handleFocus = (event: React.FocusEvent<HTMLElement>) => {
|
|
292
|
+
tooltipManager.showTooltip(
|
|
293
|
+
tooltipId.current,
|
|
294
|
+
content,
|
|
295
|
+
event.currentTarget as HTMLElement,
|
|
296
|
+
side,
|
|
297
|
+
sideOffset
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const handleBlur = () => {
|
|
302
|
+
tooltipManager.hideTooltip(tooltipId.current)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const childrenWithHandlers = React.cloneElement(children as React.ReactElement, {
|
|
306
|
+
onMouseEnter: handleMouseEnter,
|
|
307
|
+
onMouseLeave: handleMouseLeave,
|
|
308
|
+
onFocus: handleFocus,
|
|
309
|
+
onBlur: handleBlur,
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
return childrenWithHandlers
|
|
313
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import classNames from 'classnames'
|
|
2
|
+
import { Slot } from 'radix-ui'
|
|
3
|
+
import { HTMLAttributes, ReactNode, forwardRef } from 'react'
|
|
4
|
+
|
|
5
|
+
/** @public */
|
|
6
|
+
export interface TLUiLayoutProps extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
children: ReactNode
|
|
8
|
+
asChild?: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A row, usually of UI controls like buttons, select dropdown, checkboxes, etc.
|
|
13
|
+
*
|
|
14
|
+
* @public @react
|
|
15
|
+
*/
|
|
16
|
+
export const TldrawUiRow = forwardRef<HTMLDivElement, TLUiLayoutProps>(
|
|
17
|
+
({ asChild, className, ...props }, ref) => {
|
|
18
|
+
const Component = asChild ? Slot.Root : 'div'
|
|
19
|
+
return <Component ref={ref} className={classNames('tlui-row', className)} {...props} />
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A tight grid 4 elements wide, usually of UI controls like buttons, select dropdown, checkboxes,
|
|
25
|
+
* etc.
|
|
26
|
+
*
|
|
27
|
+
* @public @react */
|
|
28
|
+
export const TldrawUiGrid = forwardRef<HTMLDivElement, TLUiLayoutProps>(
|
|
29
|
+
({ asChild, className, ...props }, ref) => {
|
|
30
|
+
const Component = asChild ? Slot.Root : 'div'
|
|
31
|
+
return <Component ref={ref} className={classNames('tlui-grid', className)} {...props} />
|
|
32
|
+
}
|
|
33
|
+
)
|
|
@@ -232,7 +232,6 @@ export function TldrawUiMenuItem<
|
|
|
232
232
|
aria-label={labelStr}
|
|
233
233
|
aria-pressed={isSelected ? 'true' : 'false'}
|
|
234
234
|
isActive={isSelected}
|
|
235
|
-
className="tlui-button-grid__button"
|
|
236
235
|
data-testid={`tools.more.${id}`}
|
|
237
236
|
data-value={id}
|
|
238
237
|
disabled={disabled}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RecursivePartial, defaultUserPreferences, track, useMaybeEditor } from '@tldraw/editor'
|
|
2
2
|
import { ReactNode } from 'react'
|
|
3
3
|
import { TLUiAssetUrls, useDefaultUiAssetUrlsWithOverrides } from '../assetUrls'
|
|
4
|
+
import { TldrawUiTooltipProvider } from '../components/primitives/TldrawUiTooltip'
|
|
4
5
|
import { ToolsProvider } from '../hooks/useTools'
|
|
5
6
|
import { TldrawUiTranslationProvider } from '../hooks/useTranslation/useTranslation'
|
|
6
7
|
import {
|
|
@@ -72,26 +73,28 @@ export const TldrawUiContextProvider = track(function TldrawUiContextProvider({
|
|
|
72
73
|
const editor = useMaybeEditor()
|
|
73
74
|
return (
|
|
74
75
|
<MimeTypeContext.Provider value={mediaMimeTypes}>
|
|
75
|
-
<
|
|
76
|
-
<
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<
|
|
82
|
-
<
|
|
83
|
-
<
|
|
84
|
-
<
|
|
85
|
-
<
|
|
86
|
-
<
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
76
|
+
<TldrawUiTooltipProvider>
|
|
77
|
+
<AssetUrlsProvider assetUrls={useDefaultUiAssetUrlsWithOverrides(assetUrls)}>
|
|
78
|
+
<TldrawUiTranslationProvider
|
|
79
|
+
overrides={useMergedTranslationOverrides(overrides)}
|
|
80
|
+
locale={editor?.user.getLocale() ?? defaultUserPreferences.locale}
|
|
81
|
+
>
|
|
82
|
+
<TldrawUiEventsProvider onEvent={onUiEvent}>
|
|
83
|
+
<TldrawUiToastsProvider>
|
|
84
|
+
<TldrawUiDialogsProvider context={'tla'}>
|
|
85
|
+
<TldrawUiA11yProvider>
|
|
86
|
+
<BreakPointProvider forceMobile={forceMobile}>
|
|
87
|
+
<TldrawUiComponentsProvider overrides={components}>
|
|
88
|
+
<InternalProviders overrides={overrides}>{children}</InternalProviders>
|
|
89
|
+
</TldrawUiComponentsProvider>
|
|
90
|
+
</BreakPointProvider>
|
|
91
|
+
</TldrawUiA11yProvider>
|
|
92
|
+
</TldrawUiDialogsProvider>
|
|
93
|
+
</TldrawUiToastsProvider>
|
|
94
|
+
</TldrawUiEventsProvider>
|
|
95
|
+
</TldrawUiTranslationProvider>
|
|
96
|
+
</AssetUrlsProvider>
|
|
97
|
+
</TldrawUiTooltipProvider>
|
|
95
98
|
</MimeTypeContext.Provider>
|
|
96
99
|
)
|
|
97
100
|
})
|
|
@@ -1266,6 +1266,21 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
1266
1266
|
},
|
|
1267
1267
|
checkbox: true,
|
|
1268
1268
|
},
|
|
1269
|
+
{
|
|
1270
|
+
id: 'toggle-ui-labels',
|
|
1271
|
+
label: {
|
|
1272
|
+
default: 'action.toggle-ui-labels',
|
|
1273
|
+
menu: 'action.toggle-ui-labels.menu',
|
|
1274
|
+
},
|
|
1275
|
+
readonlyOk: true,
|
|
1276
|
+
onSelect(source) {
|
|
1277
|
+
trackEvent('toggle-ui-labels', { source })
|
|
1278
|
+
editor.user.updateUserPreferences({
|
|
1279
|
+
showUiLabels: !editor.user.getShowUiLabels(),
|
|
1280
|
+
})
|
|
1281
|
+
},
|
|
1282
|
+
checkbox: true,
|
|
1283
|
+
},
|
|
1269
1284
|
{
|
|
1270
1285
|
id: 'toggle-edge-scrolling',
|
|
1271
1286
|
label: {
|
|
@@ -93,6 +93,8 @@ export type TLUiTranslationKey =
|
|
|
93
93
|
| 'action.toggle-reduce-motion'
|
|
94
94
|
| 'action.toggle-keyboard-shortcuts.menu'
|
|
95
95
|
| 'action.toggle-keyboard-shortcuts'
|
|
96
|
+
| 'action.toggle-ui-labels.menu'
|
|
97
|
+
| 'action.toggle-ui-labels'
|
|
96
98
|
| 'action.toggle-edge-scrolling.menu'
|
|
97
99
|
| 'action.toggle-edge-scrolling'
|
|
98
100
|
| 'action.toggle-debug-mode.menu'
|
|
@@ -298,6 +300,7 @@ export type TLUiTranslationKey =
|
|
|
298
300
|
| 'a11y.open-keyboard-shortcuts'
|
|
299
301
|
| 'menu.title'
|
|
300
302
|
| 'menu.theme'
|
|
303
|
+
| 'menu.accessibility'
|
|
301
304
|
| 'menu.copy-as'
|
|
302
305
|
| 'menu.edit'
|
|
303
306
|
| 'menu.export-as'
|
|
@@ -94,6 +94,8 @@ export const DEFAULT_TRANSLATION = {
|
|
|
94
94
|
'action.toggle-reduce-motion': 'Toggle reduce motion',
|
|
95
95
|
'action.toggle-keyboard-shortcuts.menu': 'Keyboard shortcuts',
|
|
96
96
|
'action.toggle-keyboard-shortcuts': 'Toggle keyboard shortcuts',
|
|
97
|
+
'action.toggle-ui-labels.menu': 'UI labels',
|
|
98
|
+
'action.toggle-ui-labels': 'Toggle UI labels',
|
|
97
99
|
'action.toggle-edge-scrolling.menu': 'Edge scrolling',
|
|
98
100
|
'action.toggle-edge-scrolling': 'Toggle edge scrolling',
|
|
99
101
|
'action.toggle-debug-mode.menu': 'Debug mode',
|
|
@@ -299,6 +301,7 @@ export const DEFAULT_TRANSLATION = {
|
|
|
299
301
|
'a11y.open-keyboard-shortcuts': 'Open keyboard shortcuts',
|
|
300
302
|
'menu.title': 'Menu',
|
|
301
303
|
'menu.theme': 'Theme',
|
|
304
|
+
'menu.accessibility': 'Accessibility',
|
|
302
305
|
'menu.copy-as': 'Copy as',
|
|
303
306
|
'menu.edit': 'Edit',
|
|
304
307
|
'menu.export-as': 'Export as',
|
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.5dac57cf9465'
|
|
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-07T11:30:36.117Z',
|
|
8
|
+
patch: '2025-08-07T11:30:36.117Z',
|
|
9
9
|
}
|