@allbluecn/ui 0.2.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.
- package/package.json +85 -0
- package/src/ai-command-button.tsx +36 -0
- package/src/ai-stream-text.tsx +37 -0
- package/src/alert-dialog.tsx +216 -0
- package/src/animated-theme-toggler.tsx +272 -0
- package/src/auth-client.ts +108 -0
- package/src/auth-layout.tsx +66 -0
- package/src/avatar.tsx +129 -0
- package/src/badge.tsx +66 -0
- package/src/button.tsx +84 -0
- package/src/card.tsx +120 -0
- package/src/checkbox.tsx +50 -0
- package/src/context-menu.tsx +280 -0
- package/src/dialog.tsx +183 -0
- package/src/dropdown-menu.tsx +286 -0
- package/src/empty.tsx +121 -0
- package/src/grid-pattern.tsx +87 -0
- package/src/icon-packs/index.ts +27 -0
- package/src/icon-packs/knowledge.ts +55 -0
- package/src/icon-packs/prd.ts +63 -0
- package/src/icon-packs/project.ts +59 -0
- package/src/icon-picker.tsx +68 -0
- package/src/index.ts +23 -0
- package/src/input.tsx +36 -0
- package/src/item.tsx +213 -0
- package/src/kbd.tsx +33 -0
- package/src/label.tsx +39 -0
- package/src/layout-panel-top.tsx +160 -0
- package/src/name-confirm-dialog.tsx +153 -0
- package/src/nav-float-button.tsx +301 -0
- package/src/notion-avatar.tsx +126 -0
- package/src/placeholder-page.tsx +42 -0
- package/src/popover.tsx +106 -0
- package/src/reference-inline.tsx +53 -0
- package/src/reference-search.tsx +52 -0
- package/src/resizable.tsx +67 -0
- package/src/select.tsx +207 -0
- package/src/separator.tsx +45 -0
- package/src/sheet.tsx +164 -0
- package/src/sidebar.tsx +708 -0
- package/src/skeleton.tsx +30 -0
- package/src/sonner.tsx +37 -0
- package/src/switch.tsx +48 -0
- package/src/textarea.tsx +35 -0
- package/src/timezone-provider.tsx +55 -0
- package/src/tooltip.tsx +72 -0
- package/src/use-mobile.ts +36 -0
- package/src/user-avatar.tsx +79 -0
- package/src/utils.ts +6 -0
|
@@ -0,0 +1,153 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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 { useEffect, useState } from "react"
|
|
21
|
+
import type { AvatarConfig, AvatarPart, ShapeType } from "@allbluecn/shared"
|
|
22
|
+
|
|
23
|
+
const noneParts: AvatarPart[] = ["glasses", "hair", "accessories", "details", "beard"]
|
|
24
|
+
|
|
25
|
+
const partOrder: AvatarPart[] = [
|
|
26
|
+
"face",
|
|
27
|
+
"nose",
|
|
28
|
+
"mouth",
|
|
29
|
+
"eyes",
|
|
30
|
+
"eyebrows",
|
|
31
|
+
"glasses",
|
|
32
|
+
"hair",
|
|
33
|
+
"accessories",
|
|
34
|
+
"details",
|
|
35
|
+
"beard",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
function getPreviewImagePath(part: AvatarPart, index: number): string {
|
|
39
|
+
return `/avatar/preview/${part}/${index}.svg`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const SVGFilter = `<defs>
|
|
43
|
+
<filter id="notion-avatar-filter" x="-20%" y="-20%" width="140%" height="140%" filterUnits="objectBoundingBox" primitiveUnits="userSpaceOnUse" color-interpolation-filters="linearRGB">
|
|
44
|
+
<feMorphology operator="dilate" radius="20" in="SourceAlpha" result="morphology"/>
|
|
45
|
+
<feFlood flood-color="#ffffff" flood-opacity="1" result="flood"/>
|
|
46
|
+
<feComposite in="flood" in2="morphology" operator="in" result="composite"/>
|
|
47
|
+
<feMerge result="merge">
|
|
48
|
+
<feMergeNode in="composite" result="mergeNode"/>
|
|
49
|
+
<feMergeNode in="SourceGraphic" result="mergeNode1"/>
|
|
50
|
+
</feMerge>
|
|
51
|
+
</filter>
|
|
52
|
+
</defs>`
|
|
53
|
+
|
|
54
|
+
function extractInnerSvg(svgText: string): string {
|
|
55
|
+
return svgText.replace(/<svg[^>]*>/i, "").replace(/<\/svg>/i, "").trim()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const shapeStyle: Record<ShapeType, string> = {
|
|
59
|
+
circle: "rounded-full",
|
|
60
|
+
rounded: "rounded-lg",
|
|
61
|
+
square: "rounded-none",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type NotionAvatarProps = {
|
|
65
|
+
config: AvatarConfig
|
|
66
|
+
bgColor?: string
|
|
67
|
+
shape?: ShapeType
|
|
68
|
+
className?: string
|
|
69
|
+
style?: React.CSSProperties
|
|
70
|
+
flip?: boolean
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function NotionAvatar({
|
|
74
|
+
config,
|
|
75
|
+
bgColor = "transparent",
|
|
76
|
+
shape = "circle",
|
|
77
|
+
className,
|
|
78
|
+
style,
|
|
79
|
+
flip = false,
|
|
80
|
+
}: NotionAvatarProps) {
|
|
81
|
+
const [svgContent, setSvgContent] = useState<string>("")
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
async function buildAvatar() {
|
|
85
|
+
const groups = await Promise.all(
|
|
86
|
+
partOrder.map(async (part) => {
|
|
87
|
+
const index = config[part]
|
|
88
|
+
if (noneParts.includes(part) && index === 0) return ""
|
|
89
|
+
try {
|
|
90
|
+
const res = await fetch(getPreviewImagePath(part, index))
|
|
91
|
+
const svgText = await res.text()
|
|
92
|
+
const inner = extractInnerSvg(svgText)
|
|
93
|
+
return `\n<g id="avatar-${part}"${part === "face" ? ' fill="#ffffff"' : ""}>${inner}</g>`
|
|
94
|
+
} catch {
|
|
95
|
+
return ""
|
|
96
|
+
}
|
|
97
|
+
}),
|
|
98
|
+
)
|
|
99
|
+
const flipAttr = flip ? ' transform="scale(-1,1) translate(-1080, 0)"' : ""
|
|
100
|
+
const avatarSvg = `<svg viewBox="0 0 1080 1080" fill="none" xmlns="http://www.w3.org/2000/svg" style="width:100%;height:100%">${SVGFilter}<g id="avatar"${flipAttr}>${groups.join("")}</g></svg>`
|
|
101
|
+
setSvgContent(avatarSvg)
|
|
102
|
+
}
|
|
103
|
+
buildAvatar()
|
|
104
|
+
}, [config, flip])
|
|
105
|
+
|
|
106
|
+
if (!svgContent) {
|
|
107
|
+
return (
|
|
108
|
+
<div
|
|
109
|
+
className={`${shapeStyle[shape]} overflow-hidden bg-muted animate-pulse ${className ?? ""}`}
|
|
110
|
+
style={{ aspectRatio: "1 / 1", ...style }}
|
|
111
|
+
/>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<div
|
|
117
|
+
className={`${shapeStyle[shape]} ${className ?? ""}`}
|
|
118
|
+
style={{
|
|
119
|
+
backgroundColor: bgColor === "transparent" ? undefined : bgColor,
|
|
120
|
+
aspectRatio: "1 / 1",
|
|
121
|
+
...style,
|
|
122
|
+
}}
|
|
123
|
+
dangerouslySetInnerHTML={{ __html: svgContent }}
|
|
124
|
+
/>
|
|
125
|
+
)
|
|
126
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
import { useTranslation } from "react-i18next";
|
|
19
|
+
import type { LucideIcon } from "lucide-react";
|
|
20
|
+
|
|
21
|
+
type PlaceholderPageProps = {
|
|
22
|
+
title: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
icon: LucideIcon;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export function PlaceholderPage({ title, description, icon: Icon }: PlaceholderPageProps) {
|
|
28
|
+
const { t } = useTranslation('common')
|
|
29
|
+
return (
|
|
30
|
+
<div className="flex h-full min-h-[60vh] items-center justify-center">
|
|
31
|
+
<div className="flex flex-col items-center gap-4 rounded-xl border bg-card p-12 text-center shadow-sm">
|
|
32
|
+
<div className="flex size-16 items-center justify-center rounded-full bg-muted">
|
|
33
|
+
<Icon className="size-8 text-muted-foreground" />
|
|
34
|
+
</div>
|
|
35
|
+
<h1 className="text-xl font-semibold">{title}</h1>
|
|
36
|
+
<p className="text-sm text-muted-foreground">
|
|
37
|
+
{description ?? t('placeholder.developing')}
|
|
38
|
+
</p>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|