tldraw 3.16.0-canary.65a1804c722b → 3.16.0-canary.66da2a5c5813

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.
Files changed (144) hide show
  1. package/dist-cjs/index.d.ts +132 -101
  2. package/dist-cjs/index.js +25 -14
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/shapes/shared/PlainTextLabel.js +1 -3
  5. package/dist-cjs/lib/shapes/shared/PlainTextLabel.js.map +2 -2
  6. package/dist-cjs/lib/shapes/shared/useEditablePlainText.js +0 -2
  7. package/dist-cjs/lib/shapes/shared/useEditablePlainText.js.map +2 -2
  8. package/dist-cjs/lib/shapes/shared/useImageOrVideoAsset.js +0 -2
  9. package/dist-cjs/lib/shapes/shared/useImageOrVideoAsset.js.map +2 -2
  10. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanel.js +9 -4
  11. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanel.js.map +2 -2
  12. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js +255 -316
  13. package/dist-cjs/lib/ui/components/StylePanel/DefaultStylePanelContent.js.map +2 -2
  14. package/dist-cjs/lib/ui/components/{primitives/TldrawUiButtonPicker.js → StylePanel/StylePanelButtonPicker.js} +52 -45
  15. package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js.map +7 -0
  16. package/dist-cjs/lib/ui/components/StylePanel/StylePanelContext.js +68 -0
  17. package/dist-cjs/lib/ui/components/StylePanel/StylePanelContext.js.map +7 -0
  18. package/dist-cjs/lib/ui/components/StylePanel/{DoubleDropdownPicker.js → StylePanelDoubleDropdownPicker.js} +23 -22
  19. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.js.map +7 -0
  20. package/dist-cjs/lib/ui/components/StylePanel/{DropdownPicker.js → StylePanelDropdownPicker.js} +23 -20
  21. package/dist-cjs/lib/ui/components/StylePanel/StylePanelDropdownPicker.js.map +7 -0
  22. package/dist-cjs/lib/ui/components/StylePanel/StylePanelSubheading.js +28 -0
  23. package/dist-cjs/lib/ui/components/StylePanel/StylePanelSubheading.js.map +7 -0
  24. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js +3 -2
  25. package/dist-cjs/lib/ui/components/Toolbar/AltTextEditor.js.map +2 -2
  26. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js +38 -9
  27. package/dist-cjs/lib/ui/components/Toolbar/DefaultImageToolbarContent.js.map +2 -2
  28. package/dist-cjs/lib/ui/components/Toolbar/DefaultVideoToolbarContent.js +15 -3
  29. package/dist-cjs/lib/ui/components/Toolbar/DefaultVideoToolbarContent.js.map +2 -2
  30. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js +3 -3
  31. package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js.map +2 -2
  32. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js +10 -1
  33. package/dist-cjs/lib/ui/components/primitives/TldrawUiContextualToolbar.js.map +2 -2
  34. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js +17 -4
  35. package/dist-cjs/lib/ui/components/primitives/TldrawUiSlider.js.map +2 -2
  36. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js +2 -0
  37. package/dist-cjs/lib/ui/components/primitives/TldrawUiToolbar.js.map +2 -2
  38. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js +4 -0
  39. package/dist-cjs/lib/ui/components/primitives/TldrawUiTooltip.js.map +2 -2
  40. package/dist-cjs/lib/ui/context/actions.js +7 -8
  41. package/dist-cjs/lib/ui/context/actions.js.map +2 -2
  42. package/dist-cjs/lib/ui/hooks/useExportAs.js +3 -2
  43. package/dist-cjs/lib/ui/hooks/useExportAs.js.map +2 -2
  44. package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
  45. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +1 -0
  46. package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +2 -2
  47. package/dist-cjs/lib/ui/version.js +3 -3
  48. package/dist-cjs/lib/ui/version.js.map +1 -1
  49. package/dist-cjs/lib/utils/export/copyAs.js +1 -2
  50. package/dist-cjs/lib/utils/export/copyAs.js.map +2 -2
  51. package/dist-cjs/lib/utils/export/export.js +0 -20
  52. package/dist-cjs/lib/utils/export/export.js.map +2 -2
  53. package/dist-cjs/lib/utils/export/exportAs.js +1 -2
  54. package/dist-cjs/lib/utils/export/exportAs.js.map +2 -2
  55. package/dist-esm/index.d.mts +132 -101
  56. package/dist-esm/index.mjs +51 -28
  57. package/dist-esm/index.mjs.map +2 -2
  58. package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs +1 -3
  59. package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs.map +2 -2
  60. package/dist-esm/lib/shapes/shared/useEditablePlainText.mjs +0 -2
  61. package/dist-esm/lib/shapes/shared/useEditablePlainText.mjs.map +2 -2
  62. package/dist-esm/lib/shapes/shared/useImageOrVideoAsset.mjs +0 -2
  63. package/dist-esm/lib/shapes/shared/useImageOrVideoAsset.mjs.map +2 -2
  64. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanel.mjs +14 -5
  65. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanel.mjs.map +2 -2
  66. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs +257 -320
  67. package/dist-esm/lib/ui/components/StylePanel/DefaultStylePanelContent.mjs.map +2 -2
  68. package/dist-esm/lib/ui/components/{primitives/TldrawUiButtonPicker.mjs → StylePanel/StylePanelButtonPicker.mjs} +54 -43
  69. package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs.map +7 -0
  70. package/dist-esm/lib/ui/components/StylePanel/StylePanelContext.mjs +48 -0
  71. package/dist-esm/lib/ui/components/StylePanel/StylePanelContext.mjs.map +7 -0
  72. package/dist-esm/lib/ui/components/StylePanel/{DoubleDropdownPicker.mjs → StylePanelDoubleDropdownPicker.mjs} +20 -19
  73. package/dist-esm/lib/ui/components/StylePanel/StylePanelDoubleDropdownPicker.mjs.map +7 -0
  74. package/dist-esm/lib/ui/components/StylePanel/{DropdownPicker.mjs → StylePanelDropdownPicker.mjs} +20 -17
  75. package/dist-esm/lib/ui/components/StylePanel/StylePanelDropdownPicker.mjs.map +7 -0
  76. package/dist-esm/lib/ui/components/StylePanel/StylePanelSubheading.mjs +8 -0
  77. package/dist-esm/lib/ui/components/StylePanel/StylePanelSubheading.mjs.map +7 -0
  78. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs +3 -2
  79. package/dist-esm/lib/ui/components/Toolbar/AltTextEditor.mjs.map +2 -2
  80. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs +38 -9
  81. package/dist-esm/lib/ui/components/Toolbar/DefaultImageToolbarContent.mjs.map +2 -2
  82. package/dist-esm/lib/ui/components/Toolbar/DefaultVideoToolbarContent.mjs +15 -3
  83. package/dist-esm/lib/ui/components/Toolbar/DefaultVideoToolbarContent.mjs.map +2 -2
  84. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs +3 -3
  85. package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs.map +2 -2
  86. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs +10 -1
  87. package/dist-esm/lib/ui/components/primitives/TldrawUiContextualToolbar.mjs.map +2 -2
  88. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs +17 -4
  89. package/dist-esm/lib/ui/components/primitives/TldrawUiSlider.mjs.map +2 -2
  90. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs +2 -0
  91. package/dist-esm/lib/ui/components/primitives/TldrawUiToolbar.mjs.map +2 -2
  92. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs +4 -0
  93. package/dist-esm/lib/ui/components/primitives/TldrawUiTooltip.mjs.map +2 -2
  94. package/dist-esm/lib/ui/context/actions.mjs +7 -8
  95. package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
  96. package/dist-esm/lib/ui/hooks/useExportAs.mjs +3 -2
  97. package/dist-esm/lib/ui/hooks/useExportAs.mjs.map +2 -2
  98. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +1 -0
  99. package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +2 -2
  100. package/dist-esm/lib/ui/version.mjs +3 -3
  101. package/dist-esm/lib/ui/version.mjs.map +1 -1
  102. package/dist-esm/lib/utils/export/copyAs.mjs +1 -2
  103. package/dist-esm/lib/utils/export/copyAs.mjs.map +2 -2
  104. package/dist-esm/lib/utils/export/export.mjs +0 -20
  105. package/dist-esm/lib/utils/export/export.mjs.map +2 -2
  106. package/dist-esm/lib/utils/export/exportAs.mjs +1 -2
  107. package/dist-esm/lib/utils/export/exportAs.mjs.map +2 -2
  108. package/package.json +3 -3
  109. package/src/index.ts +38 -21
  110. package/src/lib/shapes/shared/PlainTextLabel.tsx +0 -6
  111. package/src/lib/shapes/shared/useEditablePlainText.ts +0 -6
  112. package/src/lib/shapes/shared/useImageOrVideoAsset.ts +0 -7
  113. package/src/lib/ui/components/StylePanel/DefaultStylePanel.tsx +27 -13
  114. package/src/lib/ui/components/StylePanel/DefaultStylePanelContent.tsx +260 -381
  115. package/src/lib/ui/components/{primitives/TldrawUiButtonPicker.tsx → StylePanel/StylePanelButtonPicker.tsx} +63 -50
  116. package/src/lib/ui/components/StylePanel/StylePanelContext.tsx +63 -0
  117. package/src/lib/ui/components/StylePanel/{DoubleDropdownPicker.tsx → StylePanelDoubleDropdownPicker.tsx} +28 -19
  118. package/src/lib/ui/components/StylePanel/StylePanelDropdownPicker.tsx +119 -0
  119. package/src/lib/ui/components/StylePanel/StylePanelSubheading.tsx +9 -0
  120. package/src/lib/ui/components/Toolbar/AltTextEditor.tsx +4 -3
  121. package/src/lib/ui/components/Toolbar/DefaultImageToolbarContent.tsx +32 -15
  122. package/src/lib/ui/components/Toolbar/DefaultVideoToolbarContent.tsx +12 -4
  123. package/src/lib/ui/components/Toolbar/LinkEditor.tsx +5 -5
  124. package/src/lib/ui/components/primitives/TldrawUiContextualToolbar.tsx +6 -1
  125. package/src/lib/ui/components/primitives/TldrawUiSlider.tsx +50 -30
  126. package/src/lib/ui/components/primitives/TldrawUiToolbar.tsx +3 -0
  127. package/src/lib/ui/components/primitives/TldrawUiTooltip.tsx +6 -0
  128. package/src/lib/ui/context/actions.tsx +7 -8
  129. package/src/lib/ui/hooks/useExportAs.ts +3 -2
  130. package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +1 -0
  131. package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +1 -0
  132. package/src/lib/ui/version.ts +3 -3
  133. package/src/lib/ui.css +16 -2
  134. package/src/lib/utils/export/copyAs.ts +1 -24
  135. package/src/lib/utils/export/export.ts +0 -36
  136. package/src/lib/utils/export/exportAs.ts +1 -32
  137. package/tldraw.css +16 -2
  138. package/dist-cjs/lib/ui/components/StylePanel/DoubleDropdownPicker.js.map +0 -7
  139. package/dist-cjs/lib/ui/components/StylePanel/DropdownPicker.js.map +0 -7
  140. package/dist-cjs/lib/ui/components/primitives/TldrawUiButtonPicker.js.map +0 -7
  141. package/dist-esm/lib/ui/components/StylePanel/DoubleDropdownPicker.mjs.map +0 -7
  142. package/dist-esm/lib/ui/components/StylePanel/DropdownPicker.mjs.map +0 -7
  143. package/dist-esm/lib/ui/components/primitives/TldrawUiButtonPicker.mjs.map +0 -7
  144. package/src/lib/ui/components/StylePanel/DropdownPicker.tsx +0 -110
@@ -13,312 +13,275 @@ import {
13
13
  DefaultVerticalAlignStyle,
14
14
  GeoShapeGeoStyle,
15
15
  LineShapeSplineStyle,
16
- getDefaultColorTheme,
17
16
  kickoutOccludedShapes,
18
17
  minBy,
19
18
  useEditor,
20
- useIsDarkMode,
21
19
  useValue
22
20
  } from "@tldraw/editor";
23
- import React, { useCallback } from "react";
21
+ import React from "react";
24
22
  import { STYLES } from "../../../styles.mjs";
25
23
  import { useUiEvents } from "../../context/events.mjs";
26
24
  import { useTranslation } from "../../hooks/useTranslation/useTranslation.mjs";
27
25
  import { TldrawUiButtonIcon } from "../primitives/Button/TldrawUiButtonIcon.mjs";
28
- import { TldrawUiButtonPicker } from "../primitives/TldrawUiButtonPicker.mjs";
29
26
  import { TldrawUiSlider } from "../primitives/TldrawUiSlider.mjs";
30
27
  import { TldrawUiToolbar, TldrawUiToolbarButton } from "../primitives/TldrawUiToolbar.mjs";
31
- import { DoubleDropdownPicker } from "./DoubleDropdownPicker.mjs";
32
- import { DropdownPicker } from "./DropdownPicker.mjs";
33
- function StylePanelSubheading({ children }) {
34
- return /* @__PURE__ */ jsx("h3", { className: "tlui-style-panel__subheading", children });
35
- }
36
- function DefaultStylePanelContent({ styles }) {
37
- const isDarkMode = useIsDarkMode();
38
- if (!styles) return null;
39
- const geo = styles.get(GeoShapeGeoStyle);
40
- const arrowheadEnd = styles.get(ArrowShapeArrowheadEndStyle);
41
- const arrowheadStart = styles.get(ArrowShapeArrowheadStartStyle);
42
- const arrowKind = styles.get(ArrowShapeKindStyle);
43
- const spline = styles.get(LineShapeSplineStyle);
44
- const font = styles.get(DefaultFontStyle);
45
- const hideGeo = geo === void 0;
46
- const hideArrowHeads = arrowheadEnd === void 0 && arrowheadStart === void 0;
47
- const hideSpline = spline === void 0;
48
- const hideArrowKind = arrowKind === void 0;
49
- const hideText = font === void 0;
50
- const theme = getDefaultColorTheme({ isDarkMode });
28
+ import { StylePanelButtonPicker } from "./StylePanelButtonPicker.mjs";
29
+ import { useStylePanelContext } from "./StylePanelContext.mjs";
30
+ import { StylePanelDoubleDropdownPicker } from "./StylePanelDoubleDropdownPicker.mjs";
31
+ import { StylePanelDropdownPicker } from "./StylePanelDropdownPicker.mjs";
32
+ import { StylePanelSubheading } from "./StylePanelSubheading.mjs";
33
+ function DefaultStylePanelContent() {
51
34
  return /* @__PURE__ */ jsxs(Fragment, { children: [
52
- /* @__PURE__ */ jsx(CommonStylePickerSet, { theme, styles }),
53
- !hideText && /* @__PURE__ */ jsx(TextStylePickerSet, { theme, styles }),
54
- !(hideGeo && hideArrowHeads && hideSpline && hideArrowKind) && /* @__PURE__ */ jsxs("div", { className: "tlui-style-panel__section", children: [
55
- /* @__PURE__ */ jsx(GeoStylePickerSet, { styles }),
56
- /* @__PURE__ */ jsx(ArrowStylePickerSet, { styles }),
57
- /* @__PURE__ */ jsx(ArrowheadStylePickerSet, { styles }),
58
- /* @__PURE__ */ jsx(SplineStylePickerSet, { styles })
35
+ /* @__PURE__ */ jsxs(StylePanelSection, { children: [
36
+ /* @__PURE__ */ jsx(StylePanelColorPicker, {}),
37
+ /* @__PURE__ */ jsx(StylePanelOpacityPicker, {})
38
+ ] }),
39
+ /* @__PURE__ */ jsxs(StylePanelSection, { children: [
40
+ /* @__PURE__ */ jsx(StylePanelFillPicker, {}),
41
+ /* @__PURE__ */ jsx(StylePanelDashPicker, {}),
42
+ /* @__PURE__ */ jsx(StylePanelSizePicker, {})
43
+ ] }),
44
+ /* @__PURE__ */ jsxs(StylePanelSection, { children: [
45
+ /* @__PURE__ */ jsx(StylePanelFontPicker, {}),
46
+ /* @__PURE__ */ jsx(StylePanelTextAlignPicker, {}),
47
+ /* @__PURE__ */ jsx(StylePanelLabelAlignPicker, {})
48
+ ] }),
49
+ /* @__PURE__ */ jsxs(StylePanelSection, { children: [
50
+ /* @__PURE__ */ jsx(StylePanelGeoShapePicker, {}),
51
+ /* @__PURE__ */ jsx(StylePanelArrowKindPicker, {}),
52
+ /* @__PURE__ */ jsx(StylePanelArrowheadPicker, {}),
53
+ /* @__PURE__ */ jsx(StylePanelSplinePicker, {})
59
54
  ] })
60
55
  ] });
61
56
  }
62
- function useStyleChangeCallback() {
57
+ function StylePanelSection({ children }) {
58
+ return /* @__PURE__ */ jsx("div", { className: "tlui-style-panel__section", children });
59
+ }
60
+ function StylePanelColorPicker() {
61
+ const { styles } = useStylePanelContext();
62
+ const msg = useTranslation();
63
+ const color = styles.get(DefaultColorStyle);
64
+ if (color === void 0) return null;
65
+ return /* @__PURE__ */ jsx(
66
+ StylePanelButtonPicker,
67
+ {
68
+ title: msg("style-panel.color"),
69
+ uiType: "color",
70
+ style: DefaultColorStyle,
71
+ items: STYLES.color,
72
+ value: color
73
+ }
74
+ );
75
+ }
76
+ const tldrawSupportedOpacities = [0.1, 0.25, 0.5, 0.75, 1];
77
+ function StylePanelOpacityPicker() {
63
78
  const editor = useEditor();
79
+ const { onHistoryMark, showUiLabels } = useStylePanelContext();
80
+ const opacity = useValue("opacity", () => editor.getSharedOpacity(), [editor]);
64
81
  const trackEvent = useUiEvents();
65
- return React.useMemo(
66
- () => (function handleStyleChange(style, value) {
82
+ const msg = useTranslation();
83
+ const handleOpacityValueChange = React.useCallback(
84
+ (value) => {
85
+ const item = tldrawSupportedOpacities[value];
67
86
  editor.run(() => {
68
87
  if (editor.isIn("select")) {
69
- editor.setStyleForSelectedShapes(style, value);
88
+ editor.setOpacityForSelectedShapes(item);
70
89
  }
71
- editor.setStyleForNextShapes(style, value);
90
+ editor.setOpacityForNextShapes(item);
72
91
  editor.updateInstanceState({ isChangingStyle: true });
73
92
  });
74
- trackEvent("set-style", { source: "style-panel", id: style.id, value });
75
- }),
93
+ trackEvent("set-style", { source: "style-panel", id: "opacity", value });
94
+ },
76
95
  [editor, trackEvent]
77
96
  );
97
+ if (opacity === void 0) return null;
98
+ const opacityIndex = opacity.type === "mixed" ? -1 : tldrawSupportedOpacities.indexOf(
99
+ minBy(
100
+ tldrawSupportedOpacities,
101
+ (supportedOpacity) => Math.abs(supportedOpacity - opacity.value)
102
+ )
103
+ );
104
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
105
+ showUiLabels && /* @__PURE__ */ jsx(StylePanelSubheading, { children: msg("style-panel.opacity") }),
106
+ /* @__PURE__ */ jsx(
107
+ TldrawUiSlider,
108
+ {
109
+ "data-testid": "style.opacity",
110
+ value: opacityIndex >= 0 ? opacityIndex : tldrawSupportedOpacities.length - 1,
111
+ label: opacity.type === "mixed" ? "style-panel.mixed" : `opacity-style.${opacity.value}`,
112
+ onValueChange: handleOpacityValueChange,
113
+ steps: tldrawSupportedOpacities.length - 1,
114
+ title: msg("style-panel.opacity"),
115
+ onHistoryMark,
116
+ ariaValueModifier: 25
117
+ }
118
+ )
119
+ ] });
78
120
  }
79
- function CommonStylePickerSet({ styles, theme }) {
121
+ function StylePanelFillPicker() {
122
+ const { styles } = useStylePanelContext();
80
123
  const msg = useTranslation();
81
- const editor = useEditor();
82
- const onHistoryMark = useCallback((id) => editor.markHistoryStoppingPoint(id), [editor]);
83
- const showUiLabels = useValue("showUiLabels", () => editor.user.getShowUiLabels(), [editor]);
84
- const handleValueChange = useStyleChangeCallback();
85
- const color = styles.get(DefaultColorStyle);
86
124
  const fill = styles.get(DefaultFillStyle);
125
+ if (fill === void 0) return null;
126
+ return /* @__PURE__ */ jsx(
127
+ StylePanelButtonPicker,
128
+ {
129
+ title: msg("style-panel.fill"),
130
+ uiType: "fill",
131
+ style: DefaultFillStyle,
132
+ items: STYLES.fill,
133
+ value: fill
134
+ }
135
+ );
136
+ }
137
+ function StylePanelDashPicker() {
138
+ const { styles } = useStylePanelContext();
139
+ const msg = useTranslation();
87
140
  const dash = styles.get(DefaultDashStyle);
141
+ if (dash === void 0) return null;
142
+ return /* @__PURE__ */ jsx(
143
+ StylePanelButtonPicker,
144
+ {
145
+ title: msg("style-panel.dash"),
146
+ uiType: "dash",
147
+ style: DefaultDashStyle,
148
+ items: STYLES.dash,
149
+ value: dash
150
+ }
151
+ );
152
+ }
153
+ function StylePanelSizePicker() {
154
+ const editor = useEditor();
155
+ const { styles, onValueChange } = useStylePanelContext();
156
+ const msg = useTranslation();
88
157
  const size = styles.get(DefaultSizeStyle);
89
- const showPickers = fill !== void 0 || dash !== void 0 || size !== void 0;
90
- return /* @__PURE__ */ jsxs(Fragment, { children: [
91
- /* @__PURE__ */ jsxs("div", { className: "tlui-style-panel__section__common", "data-testid": "style.panel", children: [
92
- color === void 0 ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
93
- showUiLabels && /* @__PURE__ */ jsx(StylePanelSubheading, { children: msg("style-panel.color") }),
94
- /* @__PURE__ */ jsx(TldrawUiToolbar, { orientation: "horizontal", label: msg("style-panel.color"), children: /* @__PURE__ */ jsx(
95
- TldrawUiButtonPicker,
96
- {
97
- title: msg("style-panel.color"),
98
- uiType: "color",
99
- style: DefaultColorStyle,
100
- items: STYLES.color,
101
- value: color,
102
- onValueChange: handleValueChange,
103
- theme,
104
- onHistoryMark
105
- }
106
- ) })
107
- ] }),
108
- /* @__PURE__ */ jsx(OpacitySlider, {})
109
- ] }),
110
- showPickers && /* @__PURE__ */ jsxs("div", { className: "tlui-style-panel__section", children: [
111
- fill === void 0 ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
112
- showUiLabels && /* @__PURE__ */ jsx(StylePanelSubheading, { children: msg("style-panel.fill") }),
113
- /* @__PURE__ */ jsx(TldrawUiToolbar, { orientation: "horizontal", label: msg("style-panel.fill"), children: /* @__PURE__ */ jsx(
114
- TldrawUiButtonPicker,
115
- {
116
- title: msg("style-panel.fill"),
117
- uiType: "fill",
118
- style: DefaultFillStyle,
119
- items: STYLES.fill,
120
- value: fill,
121
- onValueChange: handleValueChange,
122
- theme,
123
- onHistoryMark
124
- }
125
- ) })
126
- ] }),
127
- dash === void 0 ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
128
- showUiLabels && /* @__PURE__ */ jsx(StylePanelSubheading, { children: msg("style-panel.dash") }),
129
- /* @__PURE__ */ jsx(TldrawUiToolbar, { orientation: "horizontal", label: msg("style-panel.dash"), children: /* @__PURE__ */ jsx(
130
- TldrawUiButtonPicker,
131
- {
132
- title: msg("style-panel.dash"),
133
- uiType: "dash",
134
- style: DefaultDashStyle,
135
- items: STYLES.dash,
136
- value: dash,
137
- onValueChange: handleValueChange,
138
- theme,
139
- onHistoryMark
140
- }
141
- ) })
142
- ] }),
143
- size === void 0 ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
144
- showUiLabels && /* @__PURE__ */ jsx(StylePanelSubheading, { children: msg("style-panel.size") }),
145
- /* @__PURE__ */ jsx(TldrawUiToolbar, { orientation: "horizontal", label: msg("style-panel.size"), children: /* @__PURE__ */ jsx(
146
- TldrawUiButtonPicker,
147
- {
148
- title: msg("style-panel.size"),
149
- uiType: "size",
150
- style: DefaultSizeStyle,
151
- items: STYLES.size,
152
- value: size,
153
- onValueChange: (style, value) => {
154
- handleValueChange(style, value);
155
- const selectedShapeIds = editor.getSelectedShapeIds();
156
- if (selectedShapeIds.length > 0) {
157
- kickoutOccludedShapes(editor, selectedShapeIds);
158
- }
159
- },
160
- theme,
161
- onHistoryMark
162
- }
163
- ) })
164
- ] })
165
- ] })
166
- ] });
158
+ if (size === void 0) return null;
159
+ return /* @__PURE__ */ jsx(
160
+ StylePanelButtonPicker,
161
+ {
162
+ title: msg("style-panel.size"),
163
+ uiType: "size",
164
+ style: DefaultSizeStyle,
165
+ items: STYLES.size,
166
+ value: size,
167
+ onValueChange: (style, value) => {
168
+ onValueChange(style, value);
169
+ const selectedShapeIds = editor.getSelectedShapeIds();
170
+ if (selectedShapeIds.length > 0) {
171
+ kickoutOccludedShapes(editor, selectedShapeIds);
172
+ }
173
+ }
174
+ }
175
+ );
167
176
  }
168
- function TextStylePickerSet({ theme, styles }) {
177
+ function StylePanelFontPicker() {
178
+ const { styles } = useStylePanelContext();
169
179
  const msg = useTranslation();
170
- const handleValueChange = useStyleChangeCallback();
171
- const editor = useEditor();
172
- const onHistoryMark = useCallback((id) => editor.markHistoryStoppingPoint(id), [editor]);
173
- const showUiLabels = useValue("showUiLabels", () => editor.user.getShowUiLabels(), [editor]);
174
- const labelStr = showUiLabels && msg("style-panel.font");
175
180
  const font = styles.get(DefaultFontStyle);
181
+ if (font === void 0) return null;
182
+ return /* @__PURE__ */ jsx(
183
+ StylePanelButtonPicker,
184
+ {
185
+ title: msg("style-panel.font"),
186
+ uiType: "font",
187
+ style: DefaultFontStyle,
188
+ items: STYLES.font,
189
+ value: font
190
+ }
191
+ );
192
+ }
193
+ function StylePanelTextAlignPicker() {
194
+ const { styles } = useStylePanelContext();
195
+ const msg = useTranslation();
176
196
  const textAlign = styles.get(DefaultTextAlignStyle);
197
+ if (textAlign === void 0) return null;
198
+ return /* @__PURE__ */ jsxs(TldrawUiToolbar, { orientation: "horizontal", label: msg("style-panel.align"), children: [
199
+ /* @__PURE__ */ jsx(
200
+ StylePanelButtonPicker,
201
+ {
202
+ title: msg("style-panel.align"),
203
+ uiType: "align",
204
+ style: DefaultTextAlignStyle,
205
+ items: STYLES.textAlign,
206
+ value: textAlign
207
+ }
208
+ ),
209
+ /* @__PURE__ */ jsx(
210
+ TldrawUiToolbarButton,
211
+ {
212
+ type: "icon",
213
+ title: msg("style-panel.vertical-align"),
214
+ "data-testid": "vertical-align",
215
+ disabled: true,
216
+ children: /* @__PURE__ */ jsx(TldrawUiButtonIcon, { icon: "vertical-align-middle" })
217
+ }
218
+ )
219
+ ] });
220
+ }
221
+ function StylePanelLabelAlignPicker() {
222
+ const { styles } = useStylePanelContext();
223
+ const msg = useTranslation();
177
224
  const labelAlign = styles.get(DefaultHorizontalAlignStyle);
178
225
  const verticalLabelAlign = styles.get(DefaultVerticalAlignStyle);
179
- if (font === void 0 && labelAlign === void 0) {
180
- return null;
181
- }
182
- return /* @__PURE__ */ jsxs("div", { className: "tlui-style-panel__section", children: [
183
- font === void 0 ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
184
- labelStr && /* @__PURE__ */ jsx(StylePanelSubheading, { children: labelStr }),
185
- /* @__PURE__ */ jsx(TldrawUiToolbar, { orientation: "horizontal", label: msg("style-panel.font"), children: /* @__PURE__ */ jsx(
186
- TldrawUiButtonPicker,
187
- {
188
- title: msg("style-panel.font"),
189
- uiType: "font",
190
- style: DefaultFontStyle,
191
- items: STYLES.font,
192
- value: font,
193
- onValueChange: handleValueChange,
194
- theme,
195
- onHistoryMark
196
- }
197
- ) })
198
- ] }),
199
- textAlign === void 0 ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
200
- showUiLabels && /* @__PURE__ */ jsx(StylePanelSubheading, { children: msg("style-panel.align") }),
201
- /* @__PURE__ */ jsxs(TldrawUiToolbar, { orientation: "horizontal", label: msg("style-panel.align"), children: [
202
- /* @__PURE__ */ jsx(
203
- TldrawUiButtonPicker,
204
- {
205
- title: msg("style-panel.align"),
206
- uiType: "align",
207
- style: DefaultTextAlignStyle,
208
- items: STYLES.textAlign,
209
- value: textAlign,
210
- onValueChange: handleValueChange,
211
- theme,
212
- onHistoryMark
213
- }
214
- ),
215
- /* @__PURE__ */ jsx(
216
- TldrawUiToolbarButton,
217
- {
218
- type: "icon",
219
- title: msg("style-panel.vertical-align"),
220
- "data-testid": "vertical-align",
221
- disabled: true,
222
- children: /* @__PURE__ */ jsx(TldrawUiButtonIcon, { icon: "vertical-align-middle" })
223
- }
224
- )
225
- ] })
226
- ] }),
227
- labelAlign === void 0 ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
228
- showUiLabels && /* @__PURE__ */ jsx(StylePanelSubheading, { children: msg("style-panel.label-align") }),
229
- /* @__PURE__ */ jsxs(TldrawUiToolbar, { orientation: "horizontal", label: msg("style-panel.label-align"), children: [
230
- /* @__PURE__ */ jsx(
231
- TldrawUiButtonPicker,
232
- {
233
- title: msg("style-panel.label-align"),
234
- uiType: "align",
235
- style: DefaultHorizontalAlignStyle,
236
- items: STYLES.horizontalAlign,
237
- value: labelAlign,
238
- onValueChange: handleValueChange,
239
- theme,
240
- onHistoryMark
241
- }
242
- ),
243
- verticalLabelAlign === void 0 ? /* @__PURE__ */ jsx(
244
- TldrawUiToolbarButton,
245
- {
246
- type: "icon",
247
- title: msg("style-panel.vertical-align"),
248
- "data-testid": "vertical-align",
249
- disabled: true,
250
- children: /* @__PURE__ */ jsx(TldrawUiButtonIcon, { icon: "vertical-align-middle" })
251
- }
252
- ) : /* @__PURE__ */ jsx(
253
- DropdownPicker,
254
- {
255
- type: "icon",
256
- id: "geo-vertical-alignment",
257
- uiType: "verticalAlign",
258
- stylePanelType: "vertical-align",
259
- style: DefaultVerticalAlignStyle,
260
- items: STYLES.verticalAlign,
261
- value: verticalLabelAlign,
262
- onValueChange: handleValueChange
263
- }
264
- )
265
- ] })
266
- ] })
226
+ if (labelAlign === void 0) return null;
227
+ return /* @__PURE__ */ jsxs(TldrawUiToolbar, { orientation: "horizontal", label: msg("style-panel.label-align"), children: [
228
+ /* @__PURE__ */ jsx(
229
+ StylePanelButtonPicker,
230
+ {
231
+ title: msg("style-panel.label-align"),
232
+ uiType: "align",
233
+ style: DefaultHorizontalAlignStyle,
234
+ items: STYLES.horizontalAlign,
235
+ value: labelAlign
236
+ }
237
+ ),
238
+ verticalLabelAlign === void 0 ? /* @__PURE__ */ jsx(
239
+ TldrawUiToolbarButton,
240
+ {
241
+ type: "icon",
242
+ title: msg("style-panel.vertical-align"),
243
+ "data-testid": "vertical-align",
244
+ disabled: true,
245
+ children: /* @__PURE__ */ jsx(TldrawUiButtonIcon, { icon: "vertical-align-middle" })
246
+ }
247
+ ) : /* @__PURE__ */ jsx(
248
+ StylePanelDropdownPicker,
249
+ {
250
+ type: "icon",
251
+ id: "geo-vertical-alignment",
252
+ uiType: "verticalAlign",
253
+ stylePanelType: "vertical-align",
254
+ style: DefaultVerticalAlignStyle,
255
+ items: STYLES.verticalAlign,
256
+ value: verticalLabelAlign
257
+ }
258
+ )
267
259
  ] });
268
260
  }
269
- function GeoStylePickerSet({ styles }) {
270
- const msg = useTranslation();
271
- const handleValueChange = useStyleChangeCallback();
261
+ function StylePanelGeoShapePicker() {
262
+ const { styles } = useStylePanelContext();
272
263
  const geo = styles.get(GeoShapeGeoStyle);
273
- if (geo === void 0) {
274
- return null;
275
- }
276
- return /* @__PURE__ */ jsx(TldrawUiToolbar, { orientation: "horizontal", label: msg("style-panel.geo"), children: /* @__PURE__ */ jsx(
277
- DropdownPicker,
264
+ if (geo === void 0) return null;
265
+ return /* @__PURE__ */ jsx(
266
+ StylePanelDropdownPicker,
278
267
  {
279
- id: "geo",
280
- type: "menu",
281
268
  label: "style-panel.geo",
269
+ type: "menu",
270
+ id: "geo",
282
271
  uiType: "geo",
283
272
  stylePanelType: "geo",
284
273
  style: GeoShapeGeoStyle,
285
274
  items: STYLES.geo,
286
- value: geo,
287
- onValueChange: handleValueChange
275
+ value: geo
288
276
  }
289
- ) });
290
- }
291
- function SplineStylePickerSet({ styles }) {
292
- const msg = useTranslation();
293
- const handleValueChange = useStyleChangeCallback();
294
- const spline = styles.get(LineShapeSplineStyle);
295
- if (spline === void 0) {
296
- return null;
297
- }
298
- return /* @__PURE__ */ jsx(TldrawUiToolbar, { orientation: "horizontal", label: msg("style-panel.spline"), children: /* @__PURE__ */ jsx(
299
- DropdownPicker,
300
- {
301
- id: "spline",
302
- type: "menu",
303
- label: "style-panel.spline",
304
- uiType: "spline",
305
- stylePanelType: "spline",
306
- style: LineShapeSplineStyle,
307
- items: STYLES.spline,
308
- value: spline,
309
- onValueChange: handleValueChange
310
- }
311
- ) });
277
+ );
312
278
  }
313
- function ArrowStylePickerSet({ styles }) {
314
- const msg = useTranslation();
315
- const handleValueChange = useStyleChangeCallback();
279
+ function StylePanelArrowKindPicker() {
280
+ const { styles } = useStylePanelContext();
316
281
  const arrowKind = styles.get(ArrowShapeKindStyle);
317
- if (arrowKind === void 0) {
318
- return null;
319
- }
320
- return /* @__PURE__ */ jsx(TldrawUiToolbar, { orientation: "horizontal", label: msg("style-panel.arrow-kind"), children: /* @__PURE__ */ jsx(
321
- DropdownPicker,
282
+ if (arrowKind === void 0) return null;
283
+ return /* @__PURE__ */ jsx(
284
+ StylePanelDropdownPicker,
322
285
  {
323
286
  id: "arrow-kind",
324
287
  type: "menu",
@@ -327,20 +290,17 @@ function ArrowStylePickerSet({ styles }) {
327
290
  stylePanelType: "arrow-kind",
328
291
  style: ArrowShapeKindStyle,
329
292
  items: STYLES.arrowKind,
330
- value: arrowKind,
331
- onValueChange: handleValueChange
293
+ value: arrowKind
332
294
  }
333
- ) });
295
+ );
334
296
  }
335
- function ArrowheadStylePickerSet({ styles }) {
336
- const handleValueChange = useStyleChangeCallback();
297
+ function StylePanelArrowheadPicker() {
298
+ const { styles } = useStylePanelContext();
337
299
  const arrowheadEnd = styles.get(ArrowShapeArrowheadEndStyle);
338
300
  const arrowheadStart = styles.get(ArrowShapeArrowheadStartStyle);
339
- if (!arrowheadEnd || !arrowheadStart) {
340
- return null;
341
- }
301
+ if (arrowheadEnd === void 0 || arrowheadStart === void 0) return null;
342
302
  return /* @__PURE__ */ jsx(
343
- DoubleDropdownPicker,
303
+ StylePanelDoubleDropdownPicker,
344
304
  {
345
305
  label: "style-panel.arrowheads",
346
306
  uiTypeA: "arrowheadStart",
@@ -351,66 +311,43 @@ function ArrowheadStylePickerSet({ styles }) {
351
311
  styleB: ArrowShapeArrowheadEndStyle,
352
312
  itemsB: STYLES.arrowheadEnd,
353
313
  valueB: arrowheadEnd,
354
- onValueChange: handleValueChange,
355
314
  labelA: "style-panel.arrowhead-start",
356
315
  labelB: "style-panel.arrowhead-end"
357
316
  }
358
317
  );
359
318
  }
360
- const tldrawSupportedOpacities = [0.1, 0.25, 0.5, 0.75, 1];
361
- function OpacitySlider() {
362
- const editor = useEditor();
363
- const onHistoryMark = useCallback((id) => editor.markHistoryStoppingPoint(id), [editor]);
364
- const showUiLabels = useValue("showUiLabels", () => editor.user.getShowUiLabels(), [editor]);
365
- const opacity = useValue("opacity", () => editor.getSharedOpacity(), [editor]);
366
- const trackEvent = useUiEvents();
367
- const msg = useTranslation();
368
- const handleOpacityValueChange = React.useCallback(
369
- (value) => {
370
- const item = tldrawSupportedOpacities[value];
371
- editor.run(() => {
372
- if (editor.isIn("select")) {
373
- editor.setOpacityForSelectedShapes(item);
374
- }
375
- editor.setOpacityForNextShapes(item);
376
- editor.updateInstanceState({ isChangingStyle: true });
377
- });
378
- trackEvent("set-style", { source: "style-panel", id: "opacity", value });
379
- },
380
- [editor, trackEvent]
381
- );
382
- if (opacity === void 0) return null;
383
- const opacityIndex = opacity.type === "mixed" ? -1 : tldrawSupportedOpacities.indexOf(
384
- minBy(
385
- tldrawSupportedOpacities,
386
- (supportedOpacity) => Math.abs(supportedOpacity - opacity.value)
387
- )
319
+ function StylePanelSplinePicker() {
320
+ const { styles } = useStylePanelContext();
321
+ const spline = styles.get(LineShapeSplineStyle);
322
+ if (spline === void 0) return null;
323
+ return /* @__PURE__ */ jsx(
324
+ StylePanelDropdownPicker,
325
+ {
326
+ type: "menu",
327
+ id: "spline",
328
+ uiType: "spline",
329
+ stylePanelType: "spline",
330
+ label: "style-panel.spline",
331
+ style: LineShapeSplineStyle,
332
+ items: STYLES.spline,
333
+ value: spline
334
+ }
388
335
  );
389
- return /* @__PURE__ */ jsxs(Fragment, { children: [
390
- showUiLabels && /* @__PURE__ */ jsx(StylePanelSubheading, { children: msg("style-panel.opacity") }),
391
- /* @__PURE__ */ jsx(
392
- TldrawUiSlider,
393
- {
394
- "data-testid": "style.opacity",
395
- value: opacityIndex >= 0 ? opacityIndex : tldrawSupportedOpacities.length - 1,
396
- label: opacity.type === "mixed" ? "style-panel.mixed" : `opacity-style.${opacity.value}`,
397
- onValueChange: handleOpacityValueChange,
398
- steps: tldrawSupportedOpacities.length - 1,
399
- title: msg("style-panel.opacity"),
400
- onHistoryMark,
401
- ariaValueModifier: 25
402
- }
403
- )
404
- ] });
405
336
  }
406
337
  export {
407
- ArrowStylePickerSet,
408
- ArrowheadStylePickerSet,
409
- CommonStylePickerSet,
410
338
  DefaultStylePanelContent,
411
- GeoStylePickerSet,
412
- OpacitySlider,
413
- SplineStylePickerSet,
414
- TextStylePickerSet
339
+ StylePanelArrowKindPicker,
340
+ StylePanelArrowheadPicker,
341
+ StylePanelColorPicker,
342
+ StylePanelDashPicker,
343
+ StylePanelFillPicker,
344
+ StylePanelFontPicker,
345
+ StylePanelGeoShapePicker,
346
+ StylePanelLabelAlignPicker,
347
+ StylePanelOpacityPicker,
348
+ StylePanelSection,
349
+ StylePanelSizePicker,
350
+ StylePanelSplinePicker,
351
+ StylePanelTextAlignPicker
415
352
  };
416
353
  //# sourceMappingURL=DefaultStylePanelContent.mjs.map