tldraw 3.16.0-canary.ca347c5375a5 → 3.16.0-canary.cf24aedcd577
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 +129 -5
- package/dist-cjs/index.js +14 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js +3 -3
- package/dist-cjs/lib/shapes/arrow/ArrowShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/arrow/arrowTargetState.js +1 -1
- package/dist-cjs/lib/shapes/arrow/arrowTargetState.js.map +2 -2
- package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js +3 -3
- package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js +12 -12
- package/dist-cjs/lib/shapes/frame/FrameShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js +2 -2
- package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js +2 -1
- package/dist-cjs/lib/shapes/geo/components/GeoShapeBody.js.map +2 -2
- package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js +5 -1
- package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/line/LineShapeUtil.js +5 -1
- package/dist-cjs/lib/shapes/line/LineShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +4 -4
- package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/ShapeFill.js +5 -5
- package/dist-cjs/lib/shapes/shared/ShapeFill.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/shapes/text/TextShapeUtil.js +2 -2
- package/dist-cjs/lib/shapes/text/TextShapeUtil.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Translating.js.map +2 -2
- package/dist-cjs/lib/ui/TldrawUi.js +14 -0
- package/dist-cjs/lib/ui/TldrawUi.js.map +3 -3
- 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 +12 -3
- 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/MobileStylePanel.js +4 -2
- package/dist-cjs/lib/ui/components/MobileStylePanel.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 +66 -21
- package/dist-cjs/lib/ui/components/Toolbar/DefaultToolbar.js.map +3 -3
- package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js +189 -80
- package/dist-cjs/lib/ui/components/Toolbar/OverflowingToolbar.js.map +3 -3
- 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 +5 -16
- 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 +30 -7
- package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +291 -0
- package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js.map +7 -0
- package/dist-cjs/lib/ui/components/primitives/layout.js +76 -0
- package/dist-cjs/lib/ui/components/primitives/layout.js.map +7 -0
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js +30 -7
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuGroup.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuItem.js +152 -2
- 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/useTools.js +76 -9
- package/dist-cjs/lib/ui/hooks/useTools.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 +129 -5
- package/dist-esm/index.mjs +25 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs +4 -3
- package/dist-esm/lib/shapes/arrow/ArrowShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/arrow/arrowTargetState.mjs +1 -1
- package/dist-esm/lib/shapes/arrow/arrowTargetState.mjs.map +2 -2
- package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs +4 -3
- package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs +13 -12
- package/dist-esm/lib/shapes/frame/FrameShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs +3 -2
- package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs +2 -1
- package/dist-esm/lib/shapes/geo/components/GeoShapeBody.mjs.map +2 -2
- package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs +6 -1
- package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/line/LineShapeUtil.mjs +6 -1
- package/dist-esm/lib/shapes/line/LineShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +5 -4
- package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/ShapeFill.mjs +6 -5
- package/dist-esm/lib/shapes/shared/ShapeFill.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/shapes/text/TextShapeUtil.mjs +3 -2
- package/dist-esm/lib/shapes/text/TextShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Translating.mjs.map +2 -2
- package/dist-esm/lib/ui/TldrawUi.mjs +16 -2
- package/dist-esm/lib/ui/TldrawUi.mjs.map +3 -3
- 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 +12 -3
- 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/MobileStylePanel.mjs +5 -2
- package/dist-esm/lib/ui/components/MobileStylePanel.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 +56 -21
- package/dist-esm/lib/ui/components/Toolbar/DefaultToolbar.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs +192 -81
- package/dist-esm/lib/ui/components/Toolbar/OverflowingToolbar.mjs.map +3 -3
- 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 +6 -6
- 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 +30 -7
- package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs +261 -0
- package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs.map +7 -0
- package/dist-esm/lib/ui/components/primitives/layout.mjs +46 -0
- package/dist-esm/lib/ui/components/primitives/layout.mjs.map +7 -0
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs +30 -7
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuGroup.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuItem.mjs +160 -4
- 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/useTools.mjs +83 -10
- package/dist-esm/lib/ui/hooks/useTools.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 +20 -0
- package/src/lib/shapes/arrow/ArrowShapeUtil.tsx +4 -3
- package/src/lib/shapes/arrow/arrowTargetState.ts +2 -1
- package/src/lib/shapes/draw/DrawShapeUtil.tsx +4 -3
- package/src/lib/shapes/frame/FrameShapeUtil.tsx +13 -14
- package/src/lib/shapes/geo/GeoShapeUtil.tsx +3 -2
- package/src/lib/shapes/geo/components/GeoShapeBody.tsx +2 -2
- package/src/lib/shapes/highlight/HighlightShapeUtil.tsx +7 -1
- package/src/lib/shapes/line/LineShapeUtil.tsx +6 -1
- package/src/lib/shapes/note/NoteShapeUtil.tsx +9 -4
- package/src/lib/shapes/shared/ShapeFill.tsx +6 -5
- package/src/lib/shapes/shared/usePrefersReducedMotion.tsx +11 -1
- package/src/lib/shapes/text/TextShapeUtil.tsx +3 -2
- package/src/lib/tools/SelectTool/childStates/Translating.ts +0 -1
- package/src/lib/ui/TldrawUi.tsx +17 -2
- package/src/lib/ui/components/AccessibilityMenu.tsx +20 -0
- package/src/lib/ui/components/ActionsMenu/DefaultActionsMenu.tsx +15 -3
- package/src/lib/ui/components/DefaultMenuPanel.tsx +4 -3
- package/src/lib/ui/components/MainMenu/DefaultMainMenuContent.tsx +4 -4
- package/src/lib/ui/components/MobileStylePanel.tsx +8 -5
- 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 +55 -23
- package/src/lib/ui/components/Toolbar/OverflowingToolbar.tsx +212 -61
- 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 +40 -37
- 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 +51 -12
- package/src/lib/ui/components/primitives/TldrawUiTooltip.tsx +343 -0
- package/src/lib/ui/components/primitives/layout.tsx +107 -0
- package/src/lib/ui/components/primitives/menus/TldrawUiMenuGroup.tsx +30 -7
- package/src/lib/ui/components/primitives/menus/TldrawUiMenuItem.tsx +218 -3
- 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 +2 -0
- package/src/lib/ui/hooks/useTools.tsx +118 -10
- 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 +199 -84
- package/src/test/arrows-megabus.test.tsx +12 -6
- package/src/test/inner-outer-margin.test.ts +315 -0
- package/tldraw.css +201 -84
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { tlmenus, useEditor } from "@tldraw/editor";
|
|
3
|
-
import classNames from "classnames";
|
|
4
3
|
import * as React from "react";
|
|
5
4
|
import { useTranslation } from "../../hooks/useTranslation/useTranslation.mjs";
|
|
6
5
|
import { TldrawUiButtonIcon } from "../primitives/Button/TldrawUiButtonIcon.mjs";
|
|
@@ -34,26 +33,28 @@ function DropdownPickerInner({
|
|
|
34
33
|
const titleStr = value.type === "mixed" ? msg("style-panel.mixed") : stylePanelName + " \u2014 " + msg(`${uiType}-style.${value.value}`);
|
|
35
34
|
const labelStr = label ? msg(label) : "";
|
|
36
35
|
const popoverId = `style panel ${id}`;
|
|
37
|
-
return /* @__PURE__ */ jsxs(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
children:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
36
|
+
return /* @__PURE__ */ jsxs(
|
|
37
|
+
TldrawUiPopover,
|
|
38
|
+
{
|
|
39
|
+
id: popoverId,
|
|
40
|
+
open: isOpen,
|
|
41
|
+
onOpenChange: setIsOpen,
|
|
42
|
+
className: "tlui-style-panel__dropdown-picker",
|
|
43
|
+
children: [
|
|
44
|
+
/* @__PURE__ */ jsx(TldrawUiPopoverTrigger, { children: /* @__PURE__ */ jsxs(
|
|
45
|
+
TldrawUiToolbarButton,
|
|
46
|
+
{
|
|
47
|
+
type,
|
|
48
|
+
"data-testid": `style.${uiType}`,
|
|
49
|
+
"data-direction": "left",
|
|
50
|
+
title: titleStr,
|
|
51
|
+
children: [
|
|
52
|
+
labelStr && /* @__PURE__ */ jsx(TldrawUiButtonLabel, { children: labelStr }),
|
|
53
|
+
/* @__PURE__ */ jsx(TldrawUiButtonIcon, { icon: icon ?? "mixed" })
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
) }),
|
|
57
|
+
/* @__PURE__ */ jsx(TldrawUiPopoverContent, { side: "left", align: "center", children: /* @__PURE__ */ jsx(TldrawUiToolbar, { orientation: "grid", label: labelStr, children: /* @__PURE__ */ jsx(TldrawUiMenuContextProvider, { type: "icons", sourceId: "style-panel", children: items.map((item) => {
|
|
57
58
|
return /* @__PURE__ */ jsx(
|
|
58
59
|
TldrawUiToolbarButton,
|
|
59
60
|
{
|
|
@@ -71,10 +72,10 @@ function DropdownPickerInner({
|
|
|
71
72
|
},
|
|
72
73
|
item.value
|
|
73
74
|
);
|
|
74
|
-
}) })
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
}) }) }) })
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
);
|
|
78
79
|
}
|
|
79
80
|
const DropdownPicker = React.memo(DropdownPickerInner);
|
|
80
81
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/ui/components/StylePanel/DropdownPicker.tsx"],
|
|
4
|
-
"sourcesContent": ["import { SharedStyle, StyleProp, tlmenus, useEditor } from '@tldraw/editor'\nimport
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { SharedStyle, StyleProp, tlmenus, useEditor } from '@tldraw/editor'\nimport * as React from 'react'\nimport { StyleValuesForUi } from '../../../styles'\nimport { TLUiTranslationKey } from '../../hooks/useTranslation/TLUiTranslationKey'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { TLUiIconType } from '../../icon-types'\nimport { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'\nimport { TldrawUiButtonLabel } from '../primitives/Button/TldrawUiButtonLabel'\nimport {\n\tTldrawUiPopover,\n\tTldrawUiPopoverContent,\n\tTldrawUiPopoverTrigger,\n} from '../primitives/TldrawUiPopover'\nimport { TldrawUiToolbar, TldrawUiToolbarButton } from '../primitives/TldrawUiToolbar'\nimport { TldrawUiMenuContextProvider } from '../primitives/menus/TldrawUiMenuContext'\n\ninterface DropdownPickerProps<T extends string> {\n\tid: string\n\tlabel?: TLUiTranslationKey | Exclude<string, TLUiTranslationKey>\n\tuiType: string\n\tstylePanelType: string\n\tstyle: StyleProp<T>\n\tvalue: SharedStyle<T>\n\titems: StyleValuesForUi<T>\n\ttype: 'icon' | 'tool' | 'menu'\n\tonValueChange(style: StyleProp<T>, value: T): void\n}\n\nfunction DropdownPickerInner<T extends string>({\n\tid,\n\tlabel,\n\tuiType,\n\tstylePanelType,\n\tstyle,\n\titems,\n\ttype,\n\tvalue,\n\tonValueChange,\n}: DropdownPickerProps<T>) {\n\tconst msg = useTranslation()\n\tconst editor = useEditor()\n\tconst [isOpen, setIsOpen] = React.useState(false)\n\n\tconst icon = React.useMemo(\n\t\t() => items.find((item) => value.type === 'shared' && item.value === value.value)?.icon,\n\t\t[items, value]\n\t)\n\n\tconst stylePanelName = msg(`style-panel.${stylePanelType}` as TLUiTranslationKey)\n\n\tconst titleStr =\n\t\tvalue.type === 'mixed'\n\t\t\t? msg('style-panel.mixed')\n\t\t\t: stylePanelName + ' \u2014 ' + msg(`${uiType}-style.${value.value}` as TLUiTranslationKey)\n\tconst labelStr = label ? msg(label) : ''\n\n\tconst popoverId = `style panel ${id}`\n\treturn (\n\t\t<TldrawUiPopover\n\t\t\tid={popoverId}\n\t\t\topen={isOpen}\n\t\t\tonOpenChange={setIsOpen}\n\t\t\tclassName=\"tlui-style-panel__dropdown-picker\"\n\t\t>\n\t\t\t<TldrawUiPopoverTrigger>\n\t\t\t\t<TldrawUiToolbarButton\n\t\t\t\t\ttype={type}\n\t\t\t\t\tdata-testid={`style.${uiType}`}\n\t\t\t\t\tdata-direction=\"left\"\n\t\t\t\t\ttitle={titleStr}\n\t\t\t\t>\n\t\t\t\t\t{labelStr && <TldrawUiButtonLabel>{labelStr}</TldrawUiButtonLabel>}\n\t\t\t\t\t<TldrawUiButtonIcon icon={(icon as TLUiIconType) ?? 'mixed'} />\n\t\t\t\t</TldrawUiToolbarButton>\n\t\t\t</TldrawUiPopoverTrigger>\n\t\t\t<TldrawUiPopoverContent side=\"left\" align=\"center\">\n\t\t\t\t<TldrawUiToolbar orientation=\"grid\" label={labelStr}>\n\t\t\t\t\t<TldrawUiMenuContextProvider type=\"icons\" sourceId=\"style-panel\">\n\t\t\t\t\t\t{items.map((item) => {\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<TldrawUiToolbarButton\n\t\t\t\t\t\t\t\t\tkey={item.value}\n\t\t\t\t\t\t\t\t\ttype=\"icon\"\n\t\t\t\t\t\t\t\t\tdata-testid={`style.${uiType}.${item.value}`}\n\t\t\t\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\t\t\t\tstylePanelName +\n\t\t\t\t\t\t\t\t\t\t' \u2014 ' +\n\t\t\t\t\t\t\t\t\t\tmsg(`${uiType}-style.${item.value}` as TLUiTranslationKey)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tisActive={icon === item.icon}\n\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\teditor.markHistoryStoppingPoint('select style dropdown item')\n\t\t\t\t\t\t\t\t\t\tonValueChange(style, item.value)\n\t\t\t\t\t\t\t\t\t\ttlmenus.deleteOpenMenu(popoverId, editor.contextId)\n\t\t\t\t\t\t\t\t\t\tsetIsOpen(false)\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<TldrawUiButtonIcon icon={item.icon} />\n\t\t\t\t\t\t\t\t</TldrawUiToolbarButton>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t})}\n\t\t\t\t\t</TldrawUiMenuContextProvider>\n\t\t\t\t</TldrawUiToolbar>\n\t\t\t</TldrawUiPopoverContent>\n\t\t</TldrawUiPopover>\n\t)\n}\n\n// need to export like this to get generics\nexport const DropdownPicker = React.memo(DropdownPickerInner) as typeof DropdownPickerInner\n"],
|
|
5
|
+
"mappings": "AAiEI,SAMc,KANd;AAjEJ,SAAiC,SAAS,iBAAiB;AAC3D,YAAY,WAAW;AAGvB,SAAS,sBAAsB;AAE/B,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AACpC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,iBAAiB,6BAA6B;AACvD,SAAS,mCAAmC;AAc5C,SAAS,oBAAsC;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAA2B;AAC1B,QAAM,MAAM,eAAe;AAC3B,QAAM,SAAS,UAAU;AACzB,QAAM,CAAC,QAAQ,SAAS,IAAI,MAAM,SAAS,KAAK;AAEhD,QAAM,OAAO,MAAM;AAAA,IAClB,MAAM,MAAM,KAAK,CAAC,SAAS,MAAM,SAAS,YAAY,KAAK,UAAU,MAAM,KAAK,GAAG;AAAA,IACnF,CAAC,OAAO,KAAK;AAAA,EACd;AAEA,QAAM,iBAAiB,IAAI,eAAe,cAAc,EAAwB;AAEhF,QAAM,WACL,MAAM,SAAS,UACZ,IAAI,mBAAmB,IACvB,iBAAiB,aAAQ,IAAI,GAAG,MAAM,UAAU,MAAM,KAAK,EAAwB;AACvF,QAAM,WAAW,QAAQ,IAAI,KAAK,IAAI;AAEtC,QAAM,YAAY,eAAe,EAAE;AACnC,SACC;AAAA,IAAC;AAAA;AAAA,MACA,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,cAAc;AAAA,MACd,WAAU;AAAA,MAEV;AAAA,4BAAC,0BACA;AAAA,UAAC;AAAA;AAAA,YACA;AAAA,YACA,eAAa,SAAS,MAAM;AAAA,YAC5B,kBAAe;AAAA,YACf,OAAO;AAAA,YAEN;AAAA,0BAAY,oBAAC,uBAAqB,oBAAS;AAAA,cAC5C,oBAAC,sBAAmB,MAAO,QAAyB,SAAS;AAAA;AAAA;AAAA,QAC9D,GACD;AAAA,QACA,oBAAC,0BAAuB,MAAK,QAAO,OAAM,UACzC,8BAAC,mBAAgB,aAAY,QAAO,OAAO,UAC1C,8BAAC,+BAA4B,MAAK,SAAQ,UAAS,eACjD,gBAAM,IAAI,CAAC,SAAS;AACpB,iBACC;AAAA,YAAC;AAAA;AAAA,cAEA,MAAK;AAAA,cACL,eAAa,SAAS,MAAM,IAAI,KAAK,KAAK;AAAA,cAC1C,OACC,iBACA,aACA,IAAI,GAAG,MAAM,UAAU,KAAK,KAAK,EAAwB;AAAA,cAE1D,UAAU,SAAS,KAAK;AAAA,cACxB,SAAS,MAAM;AACd,uBAAO,yBAAyB,4BAA4B;AAC5D,8BAAc,OAAO,KAAK,KAAK;AAC/B,wBAAQ,eAAe,WAAW,OAAO,SAAS;AAClD,0BAAU,KAAK;AAAA,cAChB;AAAA,cAEA,8BAAC,sBAAmB,MAAM,KAAK,MAAM;AAAA;AAAA,YAhBhC,KAAK;AAAA,UAiBX;AAAA,QAEF,CAAC,GACF,GACD,GACD;AAAA;AAAA;AAAA,EACD;AAEF;AAGO,MAAM,iBAAiB,MAAM,KAAK,mBAAmB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEditor, usePassThroughWheelEvents, useValue } from "@tldraw/editor";
|
|
3
|
+
import classNames from "classnames";
|
|
3
4
|
import { memo, useRef } from "react";
|
|
4
5
|
import { PORTRAIT_BREAKPOINT } from "../../constants.mjs";
|
|
5
6
|
import { useBreakpoint } from "../../context/breakpoints.mjs";
|
|
@@ -7,11 +8,19 @@ import { useTldrawUiComponents } from "../../context/components.mjs";
|
|
|
7
8
|
import { useReadonly } from "../../hooks/useReadonly.mjs";
|
|
8
9
|
import { useTranslation } from "../../hooks/useTranslation/useTranslation.mjs";
|
|
9
10
|
import { MobileStylePanel } from "../MobileStylePanel.mjs";
|
|
11
|
+
import { TldrawUiOrientationProvider } from "../primitives/layout.mjs";
|
|
10
12
|
import { TldrawUiToolbar } from "../primitives/TldrawUiToolbar.mjs";
|
|
11
13
|
import { DefaultToolbarContent } from "./DefaultToolbarContent.mjs";
|
|
12
14
|
import { OverflowingToolbar } from "./OverflowingToolbar.mjs";
|
|
13
15
|
import { ToggleToolLockedButton } from "./ToggleToolLockedButton.mjs";
|
|
14
|
-
const DefaultToolbar = memo(function DefaultToolbar2({
|
|
16
|
+
const DefaultToolbar = memo(function DefaultToolbar2({
|
|
17
|
+
children,
|
|
18
|
+
orientation = "horizontal",
|
|
19
|
+
minItems = 4,
|
|
20
|
+
minSizePx = 310,
|
|
21
|
+
maxItems = 8,
|
|
22
|
+
maxSizePx = 470
|
|
23
|
+
}) {
|
|
15
24
|
const editor = useEditor();
|
|
16
25
|
const msg = useTranslation();
|
|
17
26
|
const breakpoint = useBreakpoint();
|
|
@@ -21,26 +30,52 @@ const DefaultToolbar = memo(function DefaultToolbar2({ children }) {
|
|
|
21
30
|
usePassThroughWheelEvents(ref);
|
|
22
31
|
const { ActionsMenu, QuickActions } = useTldrawUiComponents();
|
|
23
32
|
const showQuickActions = editor.options.actionShortcutsLocation === "menu" ? false : editor.options.actionShortcutsLocation === "toolbar" ? true : breakpoint < PORTRAIT_BREAKPOINT.TABLET;
|
|
24
|
-
return /* @__PURE__ */ jsx(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
return /* @__PURE__ */ jsx(
|
|
34
|
+
TldrawUiOrientationProvider,
|
|
35
|
+
{
|
|
36
|
+
orientation,
|
|
37
|
+
tooltipSide: orientation === "horizontal" ? "top" : "right",
|
|
38
|
+
children: /* @__PURE__ */ jsx(
|
|
39
|
+
"div",
|
|
40
|
+
{
|
|
41
|
+
ref,
|
|
42
|
+
className: classNames("tlui-main-toolbar", `tlui-main-toolbar--${orientation}`),
|
|
43
|
+
children: /* @__PURE__ */ jsxs("div", { className: "tlui-main-toolbar__inner", children: [
|
|
44
|
+
/* @__PURE__ */ jsxs("div", { className: "tlui-main-toolbar__left", children: [
|
|
45
|
+
!isReadonlyMode && /* @__PURE__ */ jsxs("div", { className: "tlui-main-toolbar__extras", children: [
|
|
46
|
+
showQuickActions && /* @__PURE__ */ jsxs(
|
|
47
|
+
TldrawUiToolbar,
|
|
48
|
+
{
|
|
49
|
+
orientation,
|
|
50
|
+
className: "tlui-main-toolbar__extras__controls",
|
|
51
|
+
label: msg("actions-menu.title"),
|
|
52
|
+
children: [
|
|
53
|
+
QuickActions && /* @__PURE__ */ jsx(QuickActions, {}),
|
|
54
|
+
ActionsMenu && /* @__PURE__ */ jsx(ActionsMenu, {})
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
),
|
|
58
|
+
/* @__PURE__ */ jsx(ToggleToolLockedButton, { activeToolId })
|
|
59
|
+
] }),
|
|
60
|
+
/* @__PURE__ */ jsx(
|
|
61
|
+
OverflowingToolbar,
|
|
62
|
+
{
|
|
63
|
+
orientation,
|
|
64
|
+
sizingParentClassName: "tlui-main-toolbar",
|
|
65
|
+
minItems,
|
|
66
|
+
maxItems,
|
|
67
|
+
minSizePx,
|
|
68
|
+
maxSizePx,
|
|
69
|
+
children: children ?? /* @__PURE__ */ jsx(DefaultToolbarContent, {})
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
] }),
|
|
73
|
+
breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM && !isReadonlyMode && /* @__PURE__ */ jsx("div", { className: "tlui-main-toolbar__tools tlui-main-toolbar__mobile-style-panel", children: /* @__PURE__ */ jsx(MobileStylePanel, {}) })
|
|
74
|
+
] })
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
);
|
|
44
79
|
});
|
|
45
80
|
export {
|
|
46
81
|
DefaultToolbar
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/ui/components/Toolbar/DefaultToolbar.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useEditor, usePassThroughWheelEvents, useValue } from '@tldraw/editor'\nimport { ReactNode, memo, useRef } from 'react'\nimport { PORTRAIT_BREAKPOINT } from '../../constants'\nimport { useBreakpoint } from '../../context/breakpoints'\nimport { useTldrawUiComponents } from '../../context/components'\nimport { useReadonly } from '../../hooks/useReadonly'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { MobileStylePanel } from '../MobileStylePanel'\nimport { TldrawUiToolbar } from '../primitives/TldrawUiToolbar'\nimport { DefaultToolbarContent } from './DefaultToolbarContent'\nimport { OverflowingToolbar } from './OverflowingToolbar'\nimport { ToggleToolLockedButton } from './ToggleToolLockedButton'\n\n/** @public */\nexport interface DefaultToolbarProps {\n\tchildren?: ReactNode\n}\n\n/**\n * The default toolbar for the editor. `children` defaults to the `DefaultToolbarContent` component.\n * Depending on the screen size, the children will overflow into a drop-down menu, with the most\n * recently active item from the overflow being shown in the main toolbar.\n *\n * @public\n * @react\n */\nexport const DefaultToolbar = memo(function DefaultToolbar({
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { useEditor, usePassThroughWheelEvents, useValue } from '@tldraw/editor'\nimport classNames from 'classnames'\nimport { ReactNode, memo, useRef } from 'react'\nimport { PORTRAIT_BREAKPOINT } from '../../constants'\nimport { useBreakpoint } from '../../context/breakpoints'\nimport { useTldrawUiComponents } from '../../context/components'\nimport { useReadonly } from '../../hooks/useReadonly'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { MobileStylePanel } from '../MobileStylePanel'\nimport { TldrawUiOrientationProvider } from '../primitives/layout'\nimport { TldrawUiToolbar } from '../primitives/TldrawUiToolbar'\nimport { DefaultToolbarContent } from './DefaultToolbarContent'\nimport { OverflowingToolbar } from './OverflowingToolbar'\nimport { ToggleToolLockedButton } from './ToggleToolLockedButton'\n\n/** @public */\nexport interface DefaultToolbarProps {\n\tchildren?: ReactNode\n\torientation?: 'horizontal' | 'vertical'\n\tminItems?: number\n\tminSizePx?: number\n\tmaxItems?: number\n\tmaxSizePx?: number\n}\n\n/**\n * The default toolbar for the editor. `children` defaults to the `DefaultToolbarContent` component.\n * Depending on the screen size, the children will overflow into a drop-down menu, with the most\n * recently active item from the overflow being shown in the main toolbar.\n *\n * @public\n * @react\n */\nexport const DefaultToolbar = memo(function DefaultToolbar({\n\tchildren,\n\torientation = 'horizontal',\n\tminItems = 4,\n\tminSizePx = 310,\n\tmaxItems = 8,\n\tmaxSizePx = 470,\n}: DefaultToolbarProps) {\n\tconst editor = useEditor()\n\tconst msg = useTranslation()\n\tconst breakpoint = useBreakpoint()\n\tconst isReadonlyMode = useReadonly()\n\tconst activeToolId = useValue('current tool id', () => editor.getCurrentToolId(), [editor])\n\n\tconst ref = useRef<HTMLDivElement>(null)\n\tusePassThroughWheelEvents(ref)\n\n\tconst { ActionsMenu, QuickActions } = useTldrawUiComponents()\n\n\tconst showQuickActions =\n\t\teditor.options.actionShortcutsLocation === 'menu'\n\t\t\t? false\n\t\t\t: editor.options.actionShortcutsLocation === 'toolbar'\n\t\t\t\t? true\n\t\t\t\t: breakpoint < PORTRAIT_BREAKPOINT.TABLET\n\n\treturn (\n\t\t<TldrawUiOrientationProvider\n\t\t\torientation={orientation}\n\t\t\ttooltipSide={orientation === 'horizontal' ? 'top' : 'right'}\n\t\t>\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tclassName={classNames('tlui-main-toolbar', `tlui-main-toolbar--${orientation}`)}\n\t\t\t>\n\t\t\t\t<div className=\"tlui-main-toolbar__inner\">\n\t\t\t\t\t<div className=\"tlui-main-toolbar__left\">\n\t\t\t\t\t\t{!isReadonlyMode && (\n\t\t\t\t\t\t\t<div className=\"tlui-main-toolbar__extras\">\n\t\t\t\t\t\t\t\t{showQuickActions && (\n\t\t\t\t\t\t\t\t\t<TldrawUiToolbar\n\t\t\t\t\t\t\t\t\t\torientation={orientation}\n\t\t\t\t\t\t\t\t\t\tclassName=\"tlui-main-toolbar__extras__controls\"\n\t\t\t\t\t\t\t\t\t\tlabel={msg('actions-menu.title')}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{QuickActions && <QuickActions />}\n\t\t\t\t\t\t\t\t\t\t{ActionsMenu && <ActionsMenu />}\n\t\t\t\t\t\t\t\t\t</TldrawUiToolbar>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t<ToggleToolLockedButton activeToolId={activeToolId} />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t<OverflowingToolbar\n\t\t\t\t\t\t\torientation={orientation}\n\t\t\t\t\t\t\tsizingParentClassName=\"tlui-main-toolbar\"\n\t\t\t\t\t\t\tminItems={minItems}\n\t\t\t\t\t\t\tmaxItems={maxItems}\n\t\t\t\t\t\t\tminSizePx={minSizePx}\n\t\t\t\t\t\t\tmaxSizePx={maxSizePx}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{children ?? <DefaultToolbarContent />}\n\t\t\t\t\t\t</OverflowingToolbar>\n\t\t\t\t\t</div>\n\t\t\t\t\t{breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM && !isReadonlyMode && (\n\t\t\t\t\t\t<div className=\"tlui-main-toolbar__tools tlui-main-toolbar__mobile-style-panel\">\n\t\t\t\t\t\t\t<MobileStylePanel />\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</TldrawUiOrientationProvider>\n\t)\n})\n"],
|
|
5
|
+
"mappings": "AAyES,SAKkB,KALlB;AAzET,SAAS,WAAW,2BAA2B,gBAAgB;AAC/D,OAAO,gBAAgB;AACvB,SAAoB,MAAM,cAAc;AACxC,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AACtC,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,mCAAmC;AAC5C,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AAoBhC,MAAM,iBAAiB,KAAK,SAASA,gBAAe;AAAA,EAC1D;AAAA,EACA,cAAc;AAAA,EACd,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,YAAY;AACb,GAAwB;AACvB,QAAM,SAAS,UAAU;AACzB,QAAM,MAAM,eAAe;AAC3B,QAAM,aAAa,cAAc;AACjC,QAAM,iBAAiB,YAAY;AACnC,QAAM,eAAe,SAAS,mBAAmB,MAAM,OAAO,iBAAiB,GAAG,CAAC,MAAM,CAAC;AAE1F,QAAM,MAAM,OAAuB,IAAI;AACvC,4BAA0B,GAAG;AAE7B,QAAM,EAAE,aAAa,aAAa,IAAI,sBAAsB;AAE5D,QAAM,mBACL,OAAO,QAAQ,4BAA4B,SACxC,QACA,OAAO,QAAQ,4BAA4B,YAC1C,OACA,aAAa,oBAAoB;AAEtC,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA,aAAa,gBAAgB,eAAe,QAAQ;AAAA,MAEpD;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACA,WAAW,WAAW,qBAAqB,sBAAsB,WAAW,EAAE;AAAA,UAE9E,+BAAC,SAAI,WAAU,4BACd;AAAA,iCAAC,SAAI,WAAU,2BACb;AAAA,eAAC,kBACD,qBAAC,SAAI,WAAU,6BACb;AAAA,oCACA;AAAA,kBAAC;AAAA;AAAA,oBACA;AAAA,oBACA,WAAU;AAAA,oBACV,OAAO,IAAI,oBAAoB;AAAA,oBAE9B;AAAA,sCAAgB,oBAAC,gBAAa;AAAA,sBAC9B,eAAe,oBAAC,eAAY;AAAA;AAAA;AAAA,gBAC9B;AAAA,gBAED,oBAAC,0BAAuB,cAA4B;AAAA,iBACrD;AAAA,cAED;AAAA,gBAAC;AAAA;AAAA,kBACA;AAAA,kBACA,uBAAsB;AAAA,kBACtB;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,kBAEC,sBAAY,oBAAC,yBAAsB;AAAA;AAAA,cACrC;AAAA,eACD;AAAA,YACC,aAAa,oBAAoB,aAAa,CAAC,kBAC/C,oBAAC,SAAI,WAAU,kEACd,8BAAC,oBAAiB,GACnB;AAAA,aAEF;AAAA;AAAA,MACD;AAAA;AAAA,EACD;AAEF,CAAC;",
|
|
6
6
|
"names": ["DefaultToolbar"]
|
|
7
7
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import {
|
|
3
3
|
activeElementShouldCaptureKeys,
|
|
4
|
+
assert,
|
|
5
|
+
modulate,
|
|
4
6
|
preventDefault,
|
|
5
7
|
tlmenus,
|
|
6
8
|
useEditor,
|
|
@@ -8,7 +10,7 @@ import {
|
|
|
8
10
|
useUniqueSafeId
|
|
9
11
|
} from "@tldraw/editor";
|
|
10
12
|
import classNames from "classnames";
|
|
11
|
-
import { createContext, useEffect, useLayoutEffect,
|
|
13
|
+
import { createContext, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
12
14
|
import { PORTRAIT_BREAKPOINT } from "../../constants.mjs";
|
|
13
15
|
import { useBreakpoint } from "../../context/breakpoints.mjs";
|
|
14
16
|
import { areShortcutsDisabled } from "../../hooks/useKeyboardShortcuts.mjs";
|
|
@@ -20,6 +22,7 @@ import {
|
|
|
20
22
|
TldrawUiPopoverTrigger
|
|
21
23
|
} from "../primitives/TldrawUiPopover.mjs";
|
|
22
24
|
import { TldrawUiToolbar, TldrawUiToolbarButton } from "../primitives/TldrawUiToolbar.mjs";
|
|
25
|
+
import { TldrawUiColumn, TldrawUiRow } from "../primitives/layout.mjs";
|
|
23
26
|
import { TldrawUiMenuContextProvider } from "../primitives/menus/TldrawUiMenuContext.mjs";
|
|
24
27
|
const IsInOverflowContext = createContext(false);
|
|
25
28
|
const NUMBERED_SHORTCUT_KEYS = {
|
|
@@ -34,55 +37,130 @@ const NUMBERED_SHORTCUT_KEYS = {
|
|
|
34
37
|
"9": 8,
|
|
35
38
|
"0": 9
|
|
36
39
|
};
|
|
37
|
-
function OverflowingToolbar({
|
|
40
|
+
function OverflowingToolbar({
|
|
41
|
+
children,
|
|
42
|
+
orientation,
|
|
43
|
+
sizingParentClassName,
|
|
44
|
+
minItems,
|
|
45
|
+
minSizePx,
|
|
46
|
+
maxItems,
|
|
47
|
+
maxSizePx
|
|
48
|
+
}) {
|
|
38
49
|
const editor = useEditor();
|
|
39
50
|
const id = useUniqueSafeId();
|
|
40
51
|
const breakpoint = useBreakpoint();
|
|
41
52
|
const msg = useTranslation();
|
|
42
53
|
const rButtons = useRef([]);
|
|
43
54
|
const [isOpen, setIsOpen] = useState(false);
|
|
44
|
-
const overflowIndex = Math.min(8, 5 + breakpoint);
|
|
45
|
-
const [totalItems, setTotalItems] = useState(0);
|
|
46
55
|
const mainToolsRef = useRef(null);
|
|
56
|
+
const [overflowTools, setOverflowTools] = useState(null);
|
|
47
57
|
const [lastActiveOverflowItem, setLastActiveOverflowItem] = useState(null);
|
|
48
|
-
const
|
|
49
|
-
const activeCss = lastActiveOverflowItem ? `:not([data-value="${lastActiveOverflowItem}"])` : "";
|
|
50
|
-
return `
|
|
51
|
-
#${id}_main > *:nth-child(n + ${overflowIndex + (lastActiveOverflowItem ? 1 : 2)})${activeCss} {
|
|
52
|
-
display: none;
|
|
53
|
-
}
|
|
54
|
-
#${id}_more > *:nth-child(-n + ${overflowIndex}) {
|
|
55
|
-
display: none;
|
|
56
|
-
}
|
|
57
|
-
#${id}_more > *:nth-child(-n + ${overflowIndex + 4}) {
|
|
58
|
-
margin-top: 0;
|
|
59
|
-
}
|
|
60
|
-
`;
|
|
61
|
-
}, [lastActiveOverflowItem, id, overflowIndex]);
|
|
58
|
+
const [shouldShowOverflow, setShouldShowOverflow] = useState(false);
|
|
62
59
|
const onDomUpdate = useEvent(() => {
|
|
63
60
|
if (!mainToolsRef.current) return;
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
const sizeProp = orientation === "horizontal" ? "offsetWidth" : "offsetHeight";
|
|
62
|
+
const mainItems = collectItems(mainToolsRef.current.children);
|
|
63
|
+
const overflowItems = overflowTools ? collectItems(overflowTools.children) : null;
|
|
64
|
+
function collectItems(collection) {
|
|
65
|
+
const items = [];
|
|
66
|
+
for (const child of collection) {
|
|
67
|
+
if (child.classList.contains("tlui-main-toolbar__group")) {
|
|
68
|
+
items.push({
|
|
69
|
+
type: "group",
|
|
70
|
+
items: collectItems(child.children),
|
|
71
|
+
element: child
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
items.push({ type: "item", element: child });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return items;
|
|
71
78
|
}
|
|
72
|
-
const
|
|
73
|
-
|
|
79
|
+
const sizingParent = findParentWithClassName(mainToolsRef.current, sizingParentClassName);
|
|
80
|
+
const size = sizingParent[sizeProp];
|
|
81
|
+
const itemsToShow = Math.floor(
|
|
82
|
+
modulate(size, [minSizePx, maxSizePx], [minItems, maxItems], true)
|
|
74
83
|
);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
let mainItemCount = 0;
|
|
85
|
+
let newActiveOverflowItem = null;
|
|
86
|
+
let shouldInvalidateLastActiveOverflowItem = false;
|
|
87
|
+
const numberedButtons = [];
|
|
88
|
+
function visitItems(mainItems2, overflowItems2) {
|
|
89
|
+
if (overflowItems2) assert(mainItems2.length === overflowItems2.length);
|
|
90
|
+
let didShowAnyInMain = false;
|
|
91
|
+
let didShowAnyInOverflow2 = false;
|
|
92
|
+
for (let i = 0; i < mainItems2.length; i++) {
|
|
93
|
+
const mainItem = mainItems2[i];
|
|
94
|
+
const overflowItem = overflowItems2?.[i];
|
|
95
|
+
if (mainItem.type === "item") {
|
|
96
|
+
const isLastActiveOverflowItem = mainItem.element.getAttribute("data-value") === lastActiveOverflowItem;
|
|
97
|
+
let shouldShowInMain;
|
|
98
|
+
if (lastActiveOverflowItem) {
|
|
99
|
+
shouldShowInMain = mainItemCount < itemsToShow || isLastActiveOverflowItem;
|
|
100
|
+
} else {
|
|
101
|
+
shouldShowInMain = mainItemCount <= itemsToShow;
|
|
102
|
+
}
|
|
103
|
+
const shouldShowInOverflow = mainItemCount >= itemsToShow;
|
|
104
|
+
didShowAnyInMain ||= shouldShowInMain;
|
|
105
|
+
didShowAnyInOverflow2 ||= shouldShowInOverflow;
|
|
106
|
+
setAttribute(
|
|
107
|
+
mainItem.element,
|
|
108
|
+
"data-toolbar-visible",
|
|
109
|
+
shouldShowInMain ? "true" : "false"
|
|
110
|
+
);
|
|
111
|
+
if (overflowItem) {
|
|
112
|
+
assert(overflowItem.type === "item");
|
|
113
|
+
setAttribute(
|
|
114
|
+
overflowItem.element,
|
|
115
|
+
"data-toolbar-visible",
|
|
116
|
+
shouldShowInOverflow ? "true" : "false"
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
if (shouldShowInOverflow && mainItem.element.getAttribute("aria-pressed") === "true") {
|
|
120
|
+
newActiveOverflowItem = mainItem.element.getAttribute("data-value");
|
|
121
|
+
}
|
|
122
|
+
if (shouldShowInMain && mainItem.element.tagName === "BUTTON") {
|
|
123
|
+
numberedButtons.push(mainItem.element);
|
|
124
|
+
}
|
|
125
|
+
if (!shouldShowInOverflow && isLastActiveOverflowItem) {
|
|
126
|
+
shouldInvalidateLastActiveOverflowItem = true;
|
|
127
|
+
}
|
|
128
|
+
mainItemCount++;
|
|
129
|
+
} else {
|
|
130
|
+
let result, overflowGroup;
|
|
131
|
+
if (overflowItem) {
|
|
132
|
+
assert(overflowItem.type === "group");
|
|
133
|
+
overflowGroup = overflowItem;
|
|
134
|
+
result = visitItems(mainItem.items, overflowGroup.items);
|
|
135
|
+
} else {
|
|
136
|
+
result = visitItems(mainItem.items, null);
|
|
137
|
+
}
|
|
138
|
+
didShowAnyInMain ||= result.didShowAnyInMain;
|
|
139
|
+
didShowAnyInOverflow2 ||= result.didShowAnyInOverflow;
|
|
140
|
+
setAttribute(
|
|
141
|
+
mainItem.element,
|
|
142
|
+
"data-toolbar-visible",
|
|
143
|
+
result.didShowAnyInMain ? "true" : "false"
|
|
144
|
+
);
|
|
145
|
+
if (overflowGroup) {
|
|
146
|
+
setAttribute(
|
|
147
|
+
overflowGroup.element,
|
|
148
|
+
"data-toolbar-visible",
|
|
149
|
+
result.didShowAnyInOverflow ? "true" : "false"
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
84
153
|
}
|
|
85
|
-
|
|
154
|
+
return { didShowAnyInMain, didShowAnyInOverflow: didShowAnyInOverflow2 };
|
|
155
|
+
}
|
|
156
|
+
const { didShowAnyInOverflow } = visitItems(mainItems, overflowItems);
|
|
157
|
+
setShouldShowOverflow(didShowAnyInOverflow);
|
|
158
|
+
if (newActiveOverflowItem) {
|
|
159
|
+
setLastActiveOverflowItem(newActiveOverflowItem);
|
|
160
|
+
} else if (shouldInvalidateLastActiveOverflowItem) {
|
|
161
|
+
setLastActiveOverflowItem(null);
|
|
162
|
+
}
|
|
163
|
+
rButtons.current = numberedButtons;
|
|
86
164
|
});
|
|
87
165
|
useLayoutEffect(() => {
|
|
88
166
|
onDomUpdate();
|
|
@@ -93,20 +171,26 @@ function OverflowingToolbar({ children }) {
|
|
|
93
171
|
mutationObserver.observe(mainToolsRef.current, {
|
|
94
172
|
childList: true,
|
|
95
173
|
subtree: true,
|
|
96
|
-
|
|
174
|
+
attributes: true,
|
|
175
|
+
characterData: true
|
|
97
176
|
});
|
|
177
|
+
const sizingParent = findParentWithClassName(mainToolsRef.current, sizingParentClassName);
|
|
178
|
+
const resizeObserver = new ResizeObserver(onDomUpdate);
|
|
179
|
+
resizeObserver.observe(sizingParent);
|
|
98
180
|
return () => {
|
|
99
181
|
mutationObserver.disconnect();
|
|
182
|
+
resizeObserver.disconnect();
|
|
100
183
|
};
|
|
101
|
-
}, [onDomUpdate]);
|
|
184
|
+
}, [onDomUpdate, sizingParentClassName]);
|
|
102
185
|
useEffect(() => {
|
|
103
186
|
if (!editor.options.enableToolbarKeyboardShortcuts) return;
|
|
104
187
|
function handleKeyDown(event) {
|
|
105
188
|
if (areShortcutsDisabled(editor) || activeElementShouldCaptureKeys(
|
|
106
189
|
true
|
|
107
190
|
/* allow buttons */
|
|
108
|
-
))
|
|
191
|
+
)) {
|
|
109
192
|
return;
|
|
193
|
+
}
|
|
110
194
|
if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return;
|
|
111
195
|
const index = NUMBERED_SHORTCUT_KEYS[event.key];
|
|
112
196
|
if (typeof index === "number") {
|
|
@@ -120,51 +204,78 @@ function OverflowingToolbar({ children }) {
|
|
|
120
204
|
};
|
|
121
205
|
}, [editor]);
|
|
122
206
|
const popoverId = "toolbar overflow";
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
207
|
+
const Layout = orientation === "horizontal" ? TldrawUiRow : TldrawUiColumn;
|
|
208
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
|
|
209
|
+
TldrawUiToolbar,
|
|
210
|
+
{
|
|
211
|
+
orientation,
|
|
212
|
+
className: classNames("tlui-main-toolbar__tools", {
|
|
213
|
+
"tlui-main-toolbar__tools__mobile": breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM
|
|
214
|
+
}),
|
|
215
|
+
label: msg("tool-panel.title"),
|
|
216
|
+
children: [
|
|
217
|
+
/* @__PURE__ */ jsx(Layout, { id: `${id}_main`, ref: mainToolsRef, children: /* @__PURE__ */ jsx(TldrawUiMenuContextProvider, { type: "toolbar", sourceId: "toolbar", children }) }),
|
|
218
|
+
shouldShowOverflow && /* @__PURE__ */ jsx(IsInOverflowContext.Provider, { value: true, children: /* @__PURE__ */ jsxs(TldrawUiPopover, { id: popoverId, open: isOpen, onOpenChange: setIsOpen, children: [
|
|
219
|
+
/* @__PURE__ */ jsx(TldrawUiPopoverTrigger, { children: /* @__PURE__ */ jsx(
|
|
220
|
+
TldrawUiToolbarButton,
|
|
221
|
+
{
|
|
222
|
+
title: msg("tool-panel.more"),
|
|
223
|
+
type: "tool",
|
|
224
|
+
className: "tlui-main-toolbar__overflow",
|
|
225
|
+
"data-testid": "tools.more-button",
|
|
226
|
+
children: /* @__PURE__ */ jsx(
|
|
227
|
+
TldrawUiButtonIcon,
|
|
228
|
+
{
|
|
229
|
+
icon: orientation === "horizontal" ? "chevron-up" : "chevron-right"
|
|
230
|
+
}
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
) }),
|
|
234
|
+
/* @__PURE__ */ jsx(
|
|
235
|
+
TldrawUiPopoverContent,
|
|
236
|
+
{
|
|
237
|
+
side: orientation === "horizontal" ? "top" : "right",
|
|
238
|
+
align: orientation === "horizontal" ? "center" : "end",
|
|
239
|
+
children: /* @__PURE__ */ jsx(
|
|
240
|
+
TldrawUiToolbar,
|
|
241
|
+
{
|
|
242
|
+
orientation: "grid",
|
|
243
|
+
className: "tlui-main-toolbar__overflow-content",
|
|
244
|
+
ref: setOverflowTools,
|
|
245
|
+
"data-testid": "tools.more-content",
|
|
246
|
+
label: msg("tool-panel.more"),
|
|
247
|
+
id: `${id}_more`,
|
|
248
|
+
onClick: () => {
|
|
249
|
+
tlmenus.deleteOpenMenu(popoverId, editor.contextId);
|
|
250
|
+
setIsOpen(false);
|
|
251
|
+
},
|
|
252
|
+
children: /* @__PURE__ */ jsx(TldrawUiMenuContextProvider, { type: "toolbar-overflow", sourceId: "toolbar", children })
|
|
253
|
+
}
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
)
|
|
257
|
+
] }) })
|
|
258
|
+
]
|
|
259
|
+
}
|
|
260
|
+
) });
|
|
164
261
|
}
|
|
165
262
|
const isActiveTLUiToolItem = (item, activeToolId, geoState) => {
|
|
166
263
|
return item.meta?.geo ? activeToolId === "geo" && geoState === item.meta?.geo : activeToolId === item.id;
|
|
167
264
|
};
|
|
265
|
+
function findParentWithClassName(startingElement, className) {
|
|
266
|
+
let element = startingElement;
|
|
267
|
+
while (element) {
|
|
268
|
+
if (element.classList.contains(className)) {
|
|
269
|
+
return element;
|
|
270
|
+
}
|
|
271
|
+
element = element.parentElement;
|
|
272
|
+
}
|
|
273
|
+
throw new Error("Could not find parent with class name " + className);
|
|
274
|
+
}
|
|
275
|
+
function setAttribute(element, name, value) {
|
|
276
|
+
if (element.getAttribute(name) === value) return;
|
|
277
|
+
element.setAttribute(name, value);
|
|
278
|
+
}
|
|
168
279
|
export {
|
|
169
280
|
IsInOverflowContext,
|
|
170
281
|
OverflowingToolbar,
|