@allbluecn/ui 0.3.13 → 0.4.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.
Files changed (146) hide show
  1. package/dist/ai-command-button.d.ts +10 -0
  2. package/dist/ai-command-button.js +12 -0
  3. package/dist/ai-stream-text.d.ts +9 -0
  4. package/dist/ai-stream-text.js +12 -0
  5. package/dist/alert-dialog.d.ts +20 -0
  6. package/dist/alert-dialog.js +101 -0
  7. package/dist/animated-theme-toggler.d.ts +11 -0
  8. package/dist/animated-theme-toggler.js +169 -0
  9. package/dist/auth-client.d.ts +27 -0
  10. package/dist/auth-client.js +86 -0
  11. package/dist/auth-layout.d.ts +14 -0
  12. package/dist/auth-layout.js +43 -0
  13. package/dist/avatar.d.ts +13 -0
  14. package/dist/avatar.js +51 -0
  15. package/dist/badge.d.ts +11 -0
  16. package/dist/badge.js +28 -0
  17. package/dist/button.d.ts +12 -0
  18. package/dist/button.js +48 -0
  19. package/dist/card.d.ts +13 -0
  20. package/dist/card.js +56 -0
  21. package/dist/checkbox.d.ts +6 -0
  22. package/dist/checkbox.js +22 -0
  23. package/dist/context-menu.d.ts +33 -0
  24. package/dist/context-menu.js +125 -0
  25. package/dist/dialog.d.ts +19 -0
  26. package/dist/dialog.js +95 -0
  27. package/dist/dropdown-menu.d.ts +31 -0
  28. package/dist/dropdown-menu.js +128 -0
  29. package/dist/empty.d.ts +13 -0
  30. package/dist/empty.js +59 -0
  31. package/dist/grid-pattern.d.ts +14 -0
  32. package/dist/grid-pattern.js +47 -0
  33. package/dist/icon-packs/index.d.ts +2 -0
  34. package/dist/icon-packs/index.js +4 -0
  35. package/dist/icon-packs/knowledge.d.ts +2 -0
  36. package/dist/icon-packs/knowledge.js +70 -0
  37. package/dist/icon-packs/prd.d.ts +2 -0
  38. package/dist/icon-packs/prd.js +86 -0
  39. package/dist/icon-packs/project.d.ts +2 -0
  40. package/dist/icon-packs/project.js +74 -0
  41. package/dist/icon-picker.d.ts +11 -0
  42. package/dist/icon-picker.js +39 -0
  43. package/dist/index-CQsbeClc.d.ts +17 -0
  44. package/dist/index.d.ts +7 -0
  45. package/dist/index.js +7 -0
  46. package/dist/input.d.ts +5 -0
  47. package/dist/input.js +14 -0
  48. package/dist/item.d.ts +25 -0
  49. package/dist/item.js +118 -0
  50. package/dist/kbd.d.ts +4 -0
  51. package/dist/kbd.js +12 -0
  52. package/dist/label.d.ts +6 -0
  53. package/dist/label.js +14 -0
  54. package/dist/layout-panel-top.d.ts +12 -0
  55. package/dist/layout-panel-top.js +127 -0
  56. package/dist/name-confirm-dialog.d.ts +15 -0
  57. package/dist/name-confirm-dialog.js +105 -0
  58. package/dist/nav-float-button.d.ts +12 -0
  59. package/dist/nav-float-button.js +249 -0
  60. package/dist/notion-avatar.d.ts +13 -0
  61. package/dist/notion-avatar.js +83 -0
  62. package/dist/placeholder-page.d.ts +10 -0
  63. package/dist/placeholder-page.js +28 -0
  64. package/dist/popover.d.ts +12 -0
  65. package/dist/popover.js +56 -0
  66. package/dist/reference-inline.d.ts +10 -0
  67. package/dist/reference-inline.js +35 -0
  68. package/dist/reference-search.d.ts +12 -0
  69. package/dist/reference-search.js +26 -0
  70. package/dist/resizable.d.ts +9 -0
  71. package/dist/resizable.js +28 -0
  72. package/dist/select.d.ts +17 -0
  73. package/dist/select.js +99 -0
  74. package/dist/separator.d.ts +6 -0
  75. package/dist/separator.js +17 -0
  76. package/dist/sheet.d.ts +16 -0
  77. package/dist/sheet.js +90 -0
  78. package/dist/sidebar.d.ts +71 -0
  79. package/dist/sidebar.js +369 -0
  80. package/dist/skeleton.d.ts +4 -0
  81. package/dist/skeleton.js +12 -0
  82. package/dist/sonner.d.ts +5 -0
  83. package/dist/sonner.js +19 -0
  84. package/dist/switch.d.ts +8 -0
  85. package/dist/switch.js +19 -0
  86. package/dist/textarea.d.ts +5 -0
  87. package/dist/textarea.js +13 -0
  88. package/dist/timezone-provider.d.ts +18 -0
  89. package/dist/timezone-provider.js +29 -0
  90. package/dist/tooltip.d.ts +9 -0
  91. package/dist/tooltip.js +35 -0
  92. package/dist/use-mobile.d.ts +4 -0
  93. package/dist/use-mobile.js +18 -0
  94. package/dist/user-avatar.d.ts +14 -0
  95. package/dist/user-avatar.js +34 -0
  96. package/dist/utils.d.ts +5 -0
  97. package/dist/utils.js +8 -0
  98. package/package.json +178 -49
  99. package/src/ai-command-button.tsx +0 -36
  100. package/src/ai-stream-text.tsx +0 -37
  101. package/src/alert-dialog.tsx +0 -216
  102. package/src/animated-theme-toggler.tsx +0 -272
  103. package/src/auth-client.ts +0 -108
  104. package/src/auth-layout.tsx +0 -66
  105. package/src/avatar.tsx +0 -129
  106. package/src/badge.tsx +0 -66
  107. package/src/button.tsx +0 -84
  108. package/src/card.tsx +0 -120
  109. package/src/checkbox.tsx +0 -50
  110. package/src/context-menu.tsx +0 -280
  111. package/src/dialog.tsx +0 -183
  112. package/src/dropdown-menu.tsx +0 -286
  113. package/src/empty.tsx +0 -121
  114. package/src/grid-pattern.tsx +0 -87
  115. package/src/icon-packs/index.ts +0 -27
  116. package/src/icon-packs/knowledge.ts +0 -55
  117. package/src/icon-packs/prd.ts +0 -63
  118. package/src/icon-packs/project.ts +0 -59
  119. package/src/icon-picker.tsx +0 -68
  120. package/src/index.ts +0 -23
  121. package/src/input.tsx +0 -36
  122. package/src/item.tsx +0 -213
  123. package/src/kbd.tsx +0 -33
  124. package/src/label.tsx +0 -39
  125. package/src/layout-panel-top.tsx +0 -160
  126. package/src/name-confirm-dialog.tsx +0 -153
  127. package/src/nav-float-button.tsx +0 -301
  128. package/src/notion-avatar.tsx +0 -126
  129. package/src/placeholder-page.tsx +0 -42
  130. package/src/popover.tsx +0 -106
  131. package/src/reference-inline.tsx +0 -53
  132. package/src/reference-search.tsx +0 -52
  133. package/src/resizable.tsx +0 -67
  134. package/src/select.tsx +0 -207
  135. package/src/separator.tsx +0 -45
  136. package/src/sheet.tsx +0 -164
  137. package/src/sidebar.tsx +0 -708
  138. package/src/skeleton.tsx +0 -30
  139. package/src/sonner.tsx +0 -37
  140. package/src/switch.tsx +0 -48
  141. package/src/textarea.tsx +0 -35
  142. package/src/timezone-provider.tsx +0 -55
  143. package/src/tooltip.tsx +0 -72
  144. package/src/use-mobile.ts +0 -36
  145. package/src/user-avatar.tsx +0 -79
  146. package/src/utils.ts +0 -6
@@ -1,160 +0,0 @@
1
- // SPDX-License-Identifier: AGPL-3.0-or-later
2
- // AllBlue - 理想之海
3
- // Copyright (C) 2026 AllBlue Contributors
4
- //
5
- // This program is free software: you can redistribute it and/or modify
6
- // it under the terms of the GNU Affero General Public License as published by
7
- // the Free Software Foundation, either version 3 of the License, or
8
- // (at your option) any later version.
9
- //
10
- // This program is distributed in the hope that it will be useful,
11
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- // GNU Affero General Public License for more details.
14
- //
15
- // You should have received a copy of the GNU Affero General Public License
16
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
17
-
18
- "use client";
19
-
20
- import { m, useAnimation } from "motion/react";
21
- import type { HTMLAttributes } from "react";
22
- import { forwardRef, useCallback, useImperativeHandle, useRef } from "react";
23
-
24
- import { cn } from "./utils";
25
-
26
- export interface LayoutPanelTopIconHandle {
27
- startAnimation: () => void;
28
- stopAnimation: () => void;
29
- }
30
-
31
- interface LayoutPanelTopIconProps extends HTMLAttributes<HTMLDivElement> {
32
- size?: number;
33
- }
34
-
35
- const LayoutPanelTopIcon = forwardRef<
36
- LayoutPanelTopIconHandle,
37
- LayoutPanelTopIconProps
38
- >(({ onMouseEnter, onMouseLeave, className, size = 28, ...props }, ref) => {
39
- const controls = useAnimation();
40
- const isControlledRef = useRef(false);
41
-
42
- useImperativeHandle(ref, () => {
43
- isControlledRef.current = true;
44
-
45
- return {
46
- startAnimation: () => controls.start("animate"),
47
- stopAnimation: () => controls.start("normal"),
48
- };
49
- });
50
-
51
- const handleMouseEnter = useCallback(
52
- (e: React.MouseEvent<HTMLDivElement>) => {
53
- if (isControlledRef.current) {
54
- onMouseEnter?.(e);
55
- } else {
56
- controls.start("animate");
57
- }
58
- },
59
- [controls, onMouseEnter]
60
- );
61
-
62
- const handleMouseLeave = useCallback(
63
- (e: React.MouseEvent<HTMLDivElement>) => {
64
- if (isControlledRef.current) {
65
- onMouseLeave?.(e);
66
- } else {
67
- controls.start("normal");
68
- }
69
- },
70
- [controls, onMouseLeave]
71
- );
72
-
73
- return (
74
- <div
75
- className={cn(className)}
76
- onMouseEnter={handleMouseEnter}
77
- onMouseLeave={handleMouseLeave}
78
- {...props}
79
- >
80
- <svg
81
- fill="none"
82
- height={size}
83
- stroke="currentColor"
84
- strokeLinecap="round"
85
- strokeLinejoin="round"
86
- strokeWidth="2"
87
- viewBox="0 0 24 24"
88
- width={size}
89
- xmlns="http://www.w3.org/2000/svg"
90
- >
91
- <m.rect
92
- animate={controls}
93
- height="7"
94
- initial="normal"
95
- rx="1"
96
- variants={{
97
- normal: { opacity: 1, translateY: 0 },
98
- animate: {
99
- opacity: [0, 1],
100
- translateY: [-5, 0],
101
- transition: {
102
- opacity: { duration: 0.5, times: [0.2, 1] },
103
- duration: 0.5,
104
- },
105
- },
106
- }}
107
- width="18"
108
- x="3"
109
- y="3"
110
- />
111
- <m.rect
112
- animate={controls}
113
- height="7"
114
- initial="normal"
115
- rx="1"
116
- variants={{
117
- normal: { opacity: 1, translateX: 0 },
118
- animate: {
119
- opacity: [0, 1],
120
- translateX: [-10, 0],
121
- transition: {
122
- opacity: { duration: 0.7, times: [0.5, 1] },
123
- translateX: { delay: 0.3 },
124
- duration: 0.5,
125
- },
126
- },
127
- }}
128
- width="7"
129
- x="3"
130
- y="14"
131
- />
132
- <m.rect
133
- animate={controls}
134
- height="7"
135
- initial="normal"
136
- rx="1"
137
- variants={{
138
- normal: { opacity: 1, translateX: 0 },
139
- animate: {
140
- opacity: [0, 1],
141
- translateX: [10, 0],
142
- transition: {
143
- opacity: { duration: 0.8, times: [0.5, 1] },
144
- translateX: { delay: 0.4 },
145
- duration: 0.5,
146
- },
147
- },
148
- }}
149
- width="7"
150
- x="14"
151
- y="14"
152
- />
153
- </svg>
154
- </div>
155
- );
156
- });
157
-
158
- LayoutPanelTopIcon.displayName = "LayoutPanelTopIcon";
159
-
160
- export { LayoutPanelTopIcon };
@@ -1,153 +0,0 @@
1
- // SPDX-License-Identifier: AGPL-3.0-or-later
2
- // AllBlue - 理想之海
3
- // Copyright (C) 2026 AllBlue Contributors
4
- //
5
- // This program is free software: you can redistribute it and/or modify
6
- // it under the terms of the GNU Affero General Public License as published by
7
- // the Free Software Foundation, either version 3 of the License, or
8
- // (at your option) any later version.
9
- //
10
- // This program is distributed in the hope that it will be useful,
11
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- // GNU Affero General Public License for more details.
14
- //
15
- // You should have received a copy of the GNU Affero General Public License
16
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
17
-
18
-
19
- import { useState } from "react";
20
- import type { ReactNode } from "react";
21
- import { toast } from "sonner";
22
- import { useTranslation } from "react-i18next";
23
- import { Button } from "./button";
24
- import { Input } from "./input";
25
- import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip";
26
- import {
27
- Dialog,
28
- DialogContent,
29
- DialogDescription,
30
- DialogFooter,
31
- DialogHeader,
32
- DialogTitle,
33
- } from "./dialog";
34
-
35
- interface NameConfirmDialogProps {
36
- open: boolean;
37
- onOpenChange: (open: boolean) => void;
38
- title: string;
39
- description: string;
40
- confirmText: string;
41
- expectedName: string;
42
- onConfirm: () => Promise<void>;
43
- children?: ReactNode;
44
- }
45
-
46
- export function NameConfirmDialog({
47
- open,
48
- onOpenChange,
49
- title,
50
- description,
51
- confirmText,
52
- expectedName,
53
- onConfirm,
54
- children,
55
- }: NameConfirmDialogProps) {
56
- const { t } = useTranslation('common')
57
- const [inputValue, setInputValue] = useState("");
58
- const [loading, setLoading] = useState(false);
59
- const [error, setError] = useState("");
60
-
61
- const isValid = inputValue.trim() === expectedName;
62
-
63
- const handleConfirm = async () => {
64
- if (!isValid) {
65
- setError(t('nameConfirm.invalidName'));
66
- return;
67
- }
68
-
69
- setLoading(true);
70
- setError("");
71
-
72
- try {
73
- await onConfirm();
74
- setInputValue("");
75
- onOpenChange(false);
76
- } catch (err) {
77
- setError(err instanceof Error ? err.message : t('nameConfirm.operationFailed'));
78
- } finally {
79
- setLoading(false);
80
- }
81
- };
82
-
83
- const handleOpenChange = (newOpen: boolean) => {
84
- if (!newOpen) {
85
- setInputValue("");
86
- setError("");
87
- }
88
- onOpenChange(newOpen);
89
- };
90
-
91
- return (
92
- <Dialog open={open} onOpenChange={handleOpenChange}>
93
- <DialogContent>
94
- <DialogHeader>
95
- <DialogTitle>{title}</DialogTitle>
96
- <DialogDescription>{description}</DialogDescription>
97
- </DialogHeader>
98
-
99
- <div className="space-y-4 py-4">
100
- <div className="space-y-2">
101
- <p className="text-sm text-muted-foreground">
102
- {t('nameConfirm.inputInstruction')} <Tooltip>
103
- <TooltipTrigger asChild>
104
- <button
105
- type="button"
106
- className="inline-flex cursor-pointer items-center font-medium text-foreground hover:text-primary transition-colors"
107
- onClick={(e) => {
108
- e.stopPropagation();
109
- void navigator.clipboard.writeText(expectedName);
110
- toast.success(t('nameConfirm.copied'));
111
- }}
112
- >
113
- {expectedName}
114
- </button>
115
- </TooltipTrigger>
116
- <TooltipContent side="top" className="text-xs">
117
- {t('nameConfirm.clickToCopy')}
118
- </TooltipContent>
119
- </Tooltip> {t('nameConfirm.confirmDelete')}
120
- </p>
121
- <Input
122
- value={inputValue}
123
- onChange={(e) => {
124
- setInputValue(e.target.value);
125
- setError("");
126
- }}
127
- placeholder={t('nameConfirm.inputPlaceholder', { expectedName })}
128
- />
129
- </div>
130
-
131
- {error && (
132
- <p className="text-sm text-destructive">{error}</p>
133
- )}
134
-
135
- {children}
136
- </div>
137
-
138
- <DialogFooter>
139
- <Button variant="outline" onClick={() => handleOpenChange(false)}>
140
- {t('nameConfirm.cancel')}
141
- </Button>
142
- <Button
143
- variant="destructive"
144
- onClick={handleConfirm}
145
- disabled={!isValid || loading}
146
- >
147
- {loading ? t('nameConfirm.deleting') : confirmText}
148
- </Button>
149
- </DialogFooter>
150
- </DialogContent>
151
- </Dialog>
152
- );
153
- }
@@ -1,301 +0,0 @@
1
- // SPDX-License-Identifier: AGPL-3.0-or-later
2
- // AllBlue - 理想之海
3
- // Copyright (C) 2026 AllBlue Contributors
4
- //
5
- // This program is free software: you can redistribute it and/or modify
6
- // it under the terms of the GNU Affero General Public License as published by
7
- // the Free Software Foundation, either version 3 of the License, or
8
- // (at your option) any later version.
9
- //
10
- // This program is distributed in the hope that it will be useful,
11
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- // GNU Affero General Public License for more details.
14
- //
15
- // You should have received a copy of the GNU Affero General Public License
16
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
17
-
18
-
19
- import React, { useRef, useState, useCallback, useEffect } from "react";
20
- import { useTranslation } from "react-i18next";
21
- import { Button } from "./button";
22
- import { Minimize2, ArrowDownToLine } from "lucide-react";
23
- import {
24
- Tooltip,
25
- TooltipContent,
26
- TooltipProvider,
27
- TooltipTrigger,
28
- } from "./tooltip";
29
-
30
- type Corner = "top-left" | "top-right" | "bottom-left" | "bottom-right";
31
-
32
- interface NavFloatButtonProps {
33
- containerRef?: React.RefObject<HTMLDivElement | null>;
34
- showExitFullscreen?: boolean;
35
- showExpandHeader?: boolean;
36
- onExitFullscreen?: () => void;
37
- onExpandHeader?: () => void;
38
- }
39
-
40
- const BUTTON_SIZE = 40;
41
-
42
- const getCornerRadius = (corner: Corner, mode: "expand" | "exit"): string => {
43
- const radius = "14px";
44
- const small = "14px";
45
-
46
- if (mode === "expand") {
47
- switch (corner) {
48
- case "top-left":
49
- return `${radius} 0 ${radius} 0`;
50
- case "top-right":
51
- return `0 ${radius} 0 ${radius}`;
52
- case "bottom-left":
53
- return `0 ${radius} 0 ${radius}`;
54
- case "bottom-right":
55
- return `${radius} 0 ${radius} 0`;
56
- }
57
- } else {
58
- switch (corner) {
59
- case "top-left":
60
- return `0 0 ${small} 0`;
61
- case "top-right":
62
- return `0 0 0 ${small}`;
63
- case "bottom-left":
64
- return `0 ${small} 0 0`;
65
- case "bottom-right":
66
- return `${small} 0 0 0`;
67
- }
68
- }
69
- };
70
-
71
- const getBorderStyle = (corner: Corner, fullBorder?: boolean) => {
72
- if (fullBorder) {
73
- return {
74
- borderLeftColor: "var(--border)",
75
- borderRightColor: "var(--border)",
76
- borderTopColor: "var(--border)",
77
- borderBottomColor: "var(--border)",
78
- };
79
- }
80
-
81
- const isLeft = corner === "top-left" || corner === "bottom-left";
82
- const isRight = corner === "top-right" || corner === "bottom-right";
83
- const isTop = corner === "top-left" || corner === "top-right";
84
- const isBottom = corner === "bottom-left" || corner === "bottom-right";
85
-
86
- return {
87
- borderLeftColor: isLeft ? "var(--background)" : "var(--border)",
88
- borderRightColor: isRight ? "var(--background)" : "var(--border)",
89
- borderTopColor: isTop ? "var(--background)" : "var(--border)",
90
- borderBottomColor: isBottom ? "var(--background)" : "var(--border)",
91
- };
92
- };
93
-
94
- export function NavFloatButton({
95
- containerRef: externalContainerRef,
96
- showExitFullscreen,
97
- showExpandHeader,
98
- onExitFullscreen,
99
- onExpandHeader,
100
- }: NavFloatButtonProps) {
101
- const { t } = useTranslation('common')
102
- const buttonRef = useRef<HTMLDivElement>(null);
103
- const containerRef = externalContainerRef as React.RefObject<HTMLDivElement | null> | undefined;
104
-
105
- const [isDragging, setIsDragging] = useState(false);
106
- const [corner, setCorner] = useState<Corner>("top-right");
107
- const [openTooltip, setOpenTooltip] = useState(false);
108
-
109
- const dragStartRef = useRef({ x: 0, y: 0, offsetX: 0, offsetY: 0 });
110
- const isMovedRef = useRef(false);
111
- const [position, setPosition] = useState({ x: 0, y: 0 });
112
-
113
- const getInitialPosition = useCallback(() => {
114
- const container = containerRef?.current;
115
- if (!container) return { x: 0, y: 0 };
116
- return { x: container.clientWidth - BUTTON_SIZE + 1, y: -1 };
117
- }, []);
118
-
119
- useEffect(() => {
120
- if (!showExitFullscreen && !showExpandHeader) return;
121
- const container = containerRef?.current;
122
- if (!container) return;
123
-
124
- const updatePosition = () => {
125
- setPosition(getInitialPosition());
126
- };
127
-
128
- updatePosition();
129
-
130
- const ro = new ResizeObserver(updatePosition);
131
- ro.observe(container);
132
- return () => ro.disconnect();
133
- }, [showExitFullscreen, showExpandHeader, getInitialPosition]);
134
-
135
- const handlePointerDown = useCallback((e: React.PointerEvent) => {
136
- const btn = buttonRef.current;
137
- if (!btn) return;
138
-
139
- e.preventDefault();
140
- e.stopPropagation();
141
- setOpenTooltip(false);
142
-
143
- btn.setPointerCapture(e.pointerId);
144
- setIsDragging(true);
145
- isMovedRef.current = false;
146
-
147
- dragStartRef.current = {
148
- x: e.clientX,
149
- y: e.clientY,
150
- offsetX: position.x,
151
- offsetY: position.y,
152
- };
153
-
154
- document.body.style.cursor = "grabbing";
155
- document.body.style.userSelect = "none";
156
- }, [position]);
157
-
158
- const handlePointerMove = useCallback((e: React.PointerEvent) => {
159
- if (!isDragging) return;
160
-
161
- const container = containerRef?.current;
162
- if (!container) return;
163
-
164
- const dx = e.clientX - dragStartRef.current.x;
165
- const dy = e.clientY - dragStartRef.current.y;
166
-
167
- if (Math.abs(dx) > 3 || Math.abs(dy) > 3) {
168
- isMovedRef.current = true;
169
- }
170
-
171
- const maxX = container.clientWidth - BUTTON_SIZE;
172
- const maxY = container.clientHeight - BUTTON_SIZE;
173
-
174
- const newX = Math.max(-1, Math.min(maxX + 1, dragStartRef.current.offsetX + dx));
175
- const newY = Math.max(-1, Math.min(maxY + 1, dragStartRef.current.offsetY + dy));
176
-
177
- setPosition({ x: newX, y: newY });
178
- }, [isDragging]);
179
-
180
- const handlePointerUp = useCallback((e: React.PointerEvent) => {
181
- const btn = buttonRef.current;
182
- if (!btn || !isDragging) return;
183
-
184
- btn.releasePointerCapture(e.pointerId);
185
- setIsDragging(false);
186
- document.body.style.cursor = "";
187
- document.body.style.userSelect = "";
188
-
189
- if (!isMovedRef.current) {
190
- if (showExitFullscreen && onExitFullscreen) {
191
- onExitFullscreen();
192
- }
193
- if (showExpandHeader && onExpandHeader) {
194
- onExpandHeader();
195
- }
196
- return;
197
- }
198
-
199
- const container = containerRef?.current;
200
- if (!container) return;
201
-
202
- const maxX = container.clientWidth - BUTTON_SIZE;
203
- const maxY = container.clientHeight - BUTTON_SIZE;
204
-
205
- const snapPoints = [
206
- { x: -1, y: -1, corner: "top-left" as Corner },
207
- { x: maxX + 1, y: -1, corner: "top-right" as Corner },
208
- { x: -1, y: maxY + 1, corner: "bottom-left" as Corner },
209
- { x: maxX + 1, y: maxY + 1, corner: "bottom-right" as Corner },
210
- ];
211
-
212
- let nearest = snapPoints[0];
213
- let minDist = Infinity;
214
-
215
- for (const sp of snapPoints) {
216
- const dist = Math.hypot(position.x - sp.x, position.y - sp.y);
217
- if (dist < minDist) {
218
- minDist = dist;
219
- nearest = sp;
220
- }
221
- }
222
-
223
- setCorner(nearest.corner);
224
- setPosition({ x: nearest.x, y: nearest.y });
225
- }, [isDragging, position, showExitFullscreen, showExpandHeader, onExitFullscreen, onExpandHeader]);
226
-
227
- const mode = showExpandHeader && !showExitFullscreen ? "expand" : "exit";
228
- const borderStyle = getBorderStyle(corner, isDragging);
229
-
230
- return (
231
- <TooltipProvider>
232
- <div
233
- ref={buttonRef}
234
- className="absolute z-50 select-none"
235
- style={{
236
- left: 0,
237
- top: 0,
238
- transform: `translate(${position.x}px, ${position.y}px)`,
239
- touchAction: "none",
240
- cursor: isDragging ? "grabbing" : "grab",
241
- transition: isDragging ? "none" : "transform 0.2s ease-out",
242
- }}
243
- onPointerDown={handlePointerDown}
244
- onPointerMove={handlePointerMove}
245
- onPointerUp={handlePointerUp}
246
- onPointerCancel={handlePointerUp}
247
- >
248
- <div
249
- className="bg-background/95 backdrop-blur flex items-center justify-center"
250
- style={{
251
- width: BUTTON_SIZE,
252
- height: BUTTON_SIZE,
253
- borderRadius: isDragging ? "50%" : getCornerRadius(corner, mode),
254
- borderWidth: 1,
255
- borderStyle: "solid",
256
- ...borderStyle,
257
- transition: "border-radius 0.2s ease-out, border-color 0.2s ease-out",
258
- }}
259
- >
260
- {showExitFullscreen && (
261
- <Tooltip open={openTooltip} onOpenChange={setOpenTooltip} delayDuration={0}>
262
- <TooltipTrigger asChild>
263
- <Button
264
- variant="ghost"
265
- size="sm"
266
- className="h-8 w-8"
267
- onMouseEnter={() => !isDragging && setOpenTooltip(true)}
268
- onMouseLeave={() => setOpenTooltip(false)}
269
- >
270
- <Minimize2 className="h-4 w-4" />
271
- </Button>
272
- </TooltipTrigger>
273
- <TooltipContent side="bottom" className="z-[9999]">
274
- <p>{t('navFloat.exitFullscreen')}</p>
275
- </TooltipContent>
276
- </Tooltip>
277
- )}
278
-
279
- {showExpandHeader && (
280
- <Tooltip open={openTooltip} onOpenChange={setOpenTooltip} delayDuration={0}>
281
- <TooltipTrigger asChild>
282
- <Button
283
- variant="ghost"
284
- size="sm"
285
- className="h-8 w-8"
286
- onMouseEnter={() => !isDragging && setOpenTooltip(true)}
287
- onMouseLeave={() => setOpenTooltip(false)}
288
- >
289
- <ArrowDownToLine className="h-4 w-4" />
290
- </Button>
291
- </TooltipTrigger>
292
- <TooltipContent side="bottom" className="z-[9999]">
293
- <p>{t('navFloat.showHeader')}</p>
294
- </TooltipContent>
295
- </Tooltip>
296
- )}
297
- </div>
298
- </div>
299
- </TooltipProvider>
300
- );
301
- }