@tuturuuu/ui 0.28.0 → 0.29.0

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.
@@ -32,76 +32,20 @@ import {
32
32
  import { Button } from '@tuturuuu/ui/button';
33
33
  import { Input } from '@tuturuuu/ui/input';
34
34
  import { toast } from '@tuturuuu/ui/sonner';
35
- import { Toggle } from '@tuturuuu/ui/toggle';
36
- import { Tooltip, TooltipContent, TooltipTrigger } from '@tuturuuu/ui/tooltip';
37
35
  import { cn } from '@tuturuuu/utils/format';
38
36
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
39
37
  import { TextEditorColorControls } from './color-controls';
38
+ import { type EditorCopyLabels, EditorCopyMenu } from './copy-menu';
40
39
  import {
41
40
  MAX_IMAGE_SIZE,
42
41
  MAX_VIDEO_SIZE,
43
42
  StorageQuotaError,
44
43
  } from './media-utils';
45
- import { hotkeyLabel, TOOLBAR_GROUPS, TOOLBAR_LABELS } from './toolbar-config';
44
+ import { TOOLBAR_GROUPS } from './toolbar-config';
45
+ import { ToolbarButton, ToolbarSeparator } from './toolbar-controls';
46
46
 
47
47
  type LinkEditorContext = 'bubble' | 'popover' | null;
48
48
 
49
- // ---------------------------------------------------------------------------
50
- // Shared sub-components
51
- // ---------------------------------------------------------------------------
52
-
53
- interface ToolbarButtonProps {
54
- id: string;
55
- label?: string;
56
- icon: React.ReactNode;
57
- pressed: boolean;
58
- onClick: () => void;
59
- disabled?: boolean;
60
- }
61
-
62
- /** A single toolbar toggle button wrapped with a tooltip showing name + hotkey. */
63
- function ToolbarButton({
64
- id,
65
- label: labelOverride,
66
- icon,
67
- pressed,
68
- onClick,
69
- disabled,
70
- }: ToolbarButtonProps) {
71
- const label = labelOverride ?? TOOLBAR_LABELS[id] ?? id;
72
- const shortcut = hotkeyLabel(id);
73
-
74
- return (
75
- <Tooltip>
76
- <TooltipTrigger asChild>
77
- <Toggle
78
- pressed={pressed}
79
- onPressedChange={() => onClick()}
80
- onMouseDown={(e) => e.preventDefault()}
81
- disabled={disabled}
82
- className="h-8 w-8 rounded-md border border-transparent transition-colors data-[state=on]:border-foreground/10 data-[state=on]:bg-dynamic-surface/80 data-[state=on]:text-foreground"
83
- aria-label={label}
84
- >
85
- {icon}
86
- </Toggle>
87
- </TooltipTrigger>
88
- <TooltipContent side="bottom" className="flex items-center gap-1.5">
89
- <span>{label}</span>
90
- {shortcut && (
91
- <kbd className="rounded bg-foreground/10 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground">
92
- {shortcut}
93
- </kbd>
94
- )}
95
- </TooltipContent>
96
- </Tooltip>
97
- );
98
- }
99
-
100
- /** Vertical divider between toolbar groups */
101
- function ToolbarSeparator() {
102
- return <div className="mx-0.5 h-5 w-px shrink-0 bg-dynamic-border/60" />;
103
- }
104
-
105
49
  // ---------------------------------------------------------------------------
106
50
  // Main ToolBar (BubbleMenu)
107
51
  // ---------------------------------------------------------------------------
@@ -898,35 +842,32 @@ export function ToolBar({
898
842
  );
899
843
  }
900
844
 
901
- // ---------------------------------------------------------------------------
902
- // Fixed Toolbar (always-visible, rendered above the editor)
903
- // ---------------------------------------------------------------------------
904
-
905
845
  interface FixedToolbarProps {
906
846
  editor: Editor | null;
847
+ leadingContent?: React.ReactNode;
907
848
  workspaceId?: string;
908
849
  onImageUpload?: (file: File) => Promise<string>;
909
850
  onConvertToTask?: () => void | Promise<void>;
910
851
  className?: string;
911
852
  ref?: React.Ref<HTMLDivElement>;
912
853
  toggleBlockLabel?: string;
854
+ copyLabels?: EditorCopyLabels;
913
855
  }
914
-
915
856
  export function FixedToolbar({
916
857
  editor,
858
+ leadingContent,
917
859
  workspaceId,
918
860
  onImageUpload,
919
861
  onConvertToTask,
920
862
  className,
921
863
  ref,
922
864
  toggleBlockLabel,
865
+ copyLabels,
923
866
  }: FixedToolbarProps) {
924
867
  const [isUploadingImage, setIsUploadingImage] = useState(false);
925
868
  const [isUploadingVideo, setIsUploadingVideo] = useState(false);
926
869
  const fileInputRef = useRef<HTMLInputElement>(null);
927
870
  const videoInputRef = useRef<HTMLInputElement>(null);
928
-
929
- // Build the formatting option map
930
871
  const formattingOptions = useMemo(() => {
931
872
  if (!editor)
932
873
  return new Map<
@@ -1140,12 +1081,11 @@ export function FixedToolbar({
1140
1081
  );
1141
1082
 
1142
1083
  if (!editor) return null;
1143
-
1144
1084
  return (
1145
1085
  <div
1146
1086
  ref={ref}
1147
1087
  className={cn(
1148
- 'sticky top-0 z-40 flex flex-wrap items-center gap-1 rounded-t-md border-dynamic-border border-b bg-background/95 px-2 py-1.5 backdrop-blur-sm',
1088
+ '@container scrollbar-hide sticky top-0 z-40 flex w-full min-w-0 max-w-full flex-nowrap items-center gap-1 overflow-x-auto overflow-y-hidden overscroll-x-contain whitespace-nowrap rounded-t-md border-dynamic-border border-b bg-background/95 px-2 py-1.5 backdrop-blur-sm',
1149
1089
  className
1150
1090
  )}
1151
1091
  >
@@ -1163,7 +1103,12 @@ export function FixedToolbar({
1163
1103
  onChange={handleVideoUpload}
1164
1104
  className="hidden"
1165
1105
  />
1166
-
1106
+ {leadingContent ? (
1107
+ <>
1108
+ <div className="shrink-0">{leadingContent}</div>
1109
+ <ToolbarSeparator />
1110
+ </>
1111
+ ) : null}
1167
1112
  {/* Grouped formatting options with separators */}
1168
1113
  {TOOLBAR_GROUPS.map((group, gi) => (
1169
1114
  <div key={gi} className="contents">
@@ -1233,6 +1178,9 @@ export function FixedToolbar({
1233
1178
  />
1234
1179
  </>
1235
1180
  )}
1181
+
1182
+ <ToolbarSeparator />
1183
+ <EditorCopyMenu editor={editor} labels={copyLabels} />
1236
1184
  </div>
1237
1185
  );
1238
1186
  }
@@ -0,0 +1,59 @@
1
+ import { Toggle } from '@tuturuuu/ui/toggle';
2
+ import { Tooltip, TooltipContent, TooltipTrigger } from '@tuturuuu/ui/tooltip';
3
+ import type { ReactNode } from 'react';
4
+ import { hotkeyLabel, TOOLBAR_LABELS } from './toolbar-config';
5
+
6
+ interface ToolbarButtonProps {
7
+ id: string;
8
+ label?: string;
9
+ icon: ReactNode;
10
+ pressed: boolean;
11
+ onClick: () => void;
12
+ disabled?: boolean;
13
+ }
14
+
15
+ export const TOOLBAR_BUTTON_CLASS_NAME =
16
+ 'h-8 w-8 shrink-0 rounded-md border border-transparent transition-colors data-[state=on]:border-foreground/10 data-[state=on]:bg-dynamic-surface/80 data-[state=on]:text-foreground';
17
+
18
+ /** A toolbar toggle with an accessible label and optional hotkey hint. */
19
+ export function ToolbarButton({
20
+ id,
21
+ label: labelOverride,
22
+ icon,
23
+ pressed,
24
+ onClick,
25
+ disabled,
26
+ }: ToolbarButtonProps) {
27
+ const label = labelOverride ?? TOOLBAR_LABELS[id] ?? id;
28
+ const shortcut = hotkeyLabel(id);
29
+
30
+ return (
31
+ <Tooltip>
32
+ <TooltipTrigger asChild>
33
+ <Toggle
34
+ pressed={pressed}
35
+ onPressedChange={() => onClick()}
36
+ onMouseDown={(event) => event.preventDefault()}
37
+ disabled={disabled}
38
+ className={TOOLBAR_BUTTON_CLASS_NAME}
39
+ aria-label={label}
40
+ >
41
+ {icon}
42
+ </Toggle>
43
+ </TooltipTrigger>
44
+ <TooltipContent side="bottom" className="flex items-center gap-1.5">
45
+ <span>{label}</span>
46
+ {shortcut ? (
47
+ <kbd className="rounded bg-foreground/10 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground">
48
+ {shortcut}
49
+ </kbd>
50
+ ) : null}
51
+ </TooltipContent>
52
+ </Tooltip>
53
+ );
54
+ }
55
+
56
+ /** Vertical divider between toolbar groups. */
57
+ export function ToolbarSeparator() {
58
+ return <div className="mx-0.5 h-5 w-px shrink-0 bg-dynamic-border/60" />;
59
+ }