Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(canvas): share from an explicit toolbar button and size work cards to the container (#21589)

Inneia8ac29925001
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 46e484f4c88..b008026a8fd 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -3594,7 +3594,7 @@
"workingPanel.tabs.pinned": "Pinned tab",
"workingPanel.tabs.unpin": "Unpin tab",
"workingPanel.title": "Working Panel",
- "workingPanel.works.canvasPublished": "Published",
+ "workingPanel.works.canvasShared": "Shared",
"workingPanel.works.canvasUntitled": "Untitled canvas",
"workingPanel.works.changeType.created": "Created",
"workingPanel.works.changeType.updated": "Updated",
diff --git a/locales/en-US/portal.json b/locales/en-US/portal.json
index 57114eae891..3e339566177 100644
--- a/locales/en-US/portal.json
+++ b/locales/en-US/portal.json
@@ -32,18 +32,21 @@
"artifacts.svg.download.svg": "Download as SVG",
"canvas.frameTitle": "Canvas preview",
"canvas.generating": "Generating v{{version}}…",
- "canvas.menu.openPublic": "Open public link",
- "canvas.menu.publish": "Publish v{{version}} to a public link",
- "canvas.menu.publishing": "Publishing…",
- "canvas.menu.updatePublic": "Update public link to v{{version}}",
"canvas.menu.versionItem": "v{{version}} · {{date}}",
"canvas.menu.versions": "Version history",
"canvas.notFound": "This canvas no longer exists or is not available to you.",
- "canvas.publish.failed": "Couldn’t publish. Try again.",
- "canvas.publish.note": "Newer versions stay private until you update the public link.",
- "canvas.publish.success": "Published v{{version}}",
"canvas.runtimeErrors": "This canvas reported errors ({{count}})",
"canvas.runtimeErrorsHint": "Some components could not render. Ask the agent to fix the canvas, or expand to see details.",
+ "canvas.share.confirmTitle": "Before you share this canvas",
+ "canvas.share.failed": "Couldn’t share. Try again.",
+ "canvas.share.note": "Newer versions stay private until you share them.",
+ "canvas.share.open": "Open share link",
+ "canvas.share.privacy": "Anyone with the link can open this canvas. Before sharing, make sure it does not contain anything you would rather keep private, such as credentials, API keys, personal information, uploaded files, or images.",
+ "canvas.share.publish": "Share v{{version}}",
+ "canvas.share.sharing": "Sharing…",
+ "canvas.share.success": "Shared v{{version}}",
+ "canvas.share.trigger": "Share",
+ "canvas.share.update": "Update share to v{{version}}",
"canvas.title": "Canvas",
"document.saveConflict": "This document was updated elsewhere. Refreshing to the latest version.",
"document.todos.allCompleted": "All tasks completed",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index e2a6af27bd6..28fdc24aa45 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -3594,7 +3594,7 @@
"workingPanel.tabs.pinned": "已固定标签页",
"workingPanel.tabs.unpin": "取消固定标签页",
"workingPanel.title": "工作面板",
- "workingPanel.works.canvasPublished": "已发布",
+ "workingPanel.works.canvasShared": "已分享",
"workingPanel.works.canvasUntitled": "未命名画布",
"workingPanel.works.changeType.created": "已创建",
"workingPanel.works.changeType.updated": "已编辑",
diff --git a/locales/zh-CN/portal.json b/locales/zh-CN/portal.json
index 0b166e1af63..8ec9ca30c66 100644
--- a/locales/zh-CN/portal.json
+++ b/locales/zh-CN/portal.json
@@ -32,18 +32,21 @@
"artifacts.svg.download.svg": "下载为 SVG",
"canvas.frameTitle": "画布预览",
"canvas.generating": "正在生成 v{{version}}…",
- "canvas.menu.openPublic": "打开公开链接",
- "canvas.menu.publish": "将 v{{version}} 发布到公开链接",
- "canvas.menu.publishing": "发布中…",
- "canvas.menu.updatePublic": "将公开链接更新到 v{{version}}",
"canvas.menu.versionItem": "v{{version}} · {{date}}",
"canvas.menu.versions": "版本历史",
"canvas.notFound": "这个画布不存在或你没有访问权限。",
- "canvas.publish.failed": "发布失败,请重试",
- "canvas.publish.note": "之后的新版本在你更新公开链接前保持私密。",
- "canvas.publish.success": "已发布 v{{version}}",
"canvas.runtimeErrors": "画布运行时报错({{count}})",
"canvas.runtimeErrorsHint": "部分组件未能渲染。可以让助手修复画布,或展开查看详情。",
+ "canvas.share.confirmTitle": "分享此画布前",
+ "canvas.share.failed": "分享失败,请重试",
+ "canvas.share.note": "之后的新版本在你更新分享前保持私密。",
+ "canvas.share.open": "打开分享链接",
+ "canvas.share.privacy": "任何拥有链接的人都可以打开此画布。分享前请确认其中不含你希望保密的内容,例如凭证、API 密钥、个人信息、上传的文件或图片。",
+ "canvas.share.publish": "分享 v{{version}}",
+ "canvas.share.sharing": "分享中…",
+ "canvas.share.success": "已分享 v{{version}}",
+ "canvas.share.trigger": "分享",
+ "canvas.share.update": "更新分享到 v{{version}}",
"canvas.title": "画布",
"document.saveConflict": "文档已在别处更新,正在刷新为最新版本",
"document.todos.allCompleted": "所有任务已完成",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index a1626302472..41c44911c41 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -3601,7 +3601,7 @@ export default {
'workingPanel.works.emptyVersions': 'No versions yet',
'workingPanel.works.error': 'Failed to load works',
'workingPanel.works.documentLoadError': 'Failed to load document',
- 'workingPanel.works.canvasPublished': 'Published',
+ 'workingPanel.works.canvasShared': 'Shared',
'workingPanel.works.canvasUntitled': 'Untitled canvas',
'workingPanel.works.changeType.created': 'Created',
'workingPanel.works.changeType.updated': 'Updated',
diff --git a/packages/locales/src/default/portal.ts b/packages/locales/src/default/portal.ts
index f1d14e1b721..3dd5d8f0c6d 100644
--- a/packages/locales/src/default/portal.ts
+++ b/packages/locales/src/default/portal.ts
@@ -42,17 +42,21 @@ export default {
'canvas.generating': 'Generating v{{version}}…',
'canvas.menu.versionItem': 'v{{version}} · {{date}}',
'canvas.menu.versions': 'Version history',
- 'canvas.menu.openPublic': 'Open public link',
- 'canvas.menu.publish': 'Publish v{{version}} to a public link',
- 'canvas.menu.publishing': 'Publishing…',
- 'canvas.menu.updatePublic': 'Update public link to v{{version}}',
'canvas.notFound': 'This canvas no longer exists or is not available to you.',
- 'canvas.publish.failed': 'Couldn’t publish. Try again.',
- 'canvas.publish.note': 'Newer versions stay private until you update the public link.',
- 'canvas.publish.success': 'Published v{{version}}',
'canvas.runtimeErrors': 'This canvas reported errors ({{count}})',
'canvas.runtimeErrorsHint':
'Some components could not render. Ask the agent to fix the canvas, or expand to see details.',
+ 'canvas.share.confirmTitle': 'Before you share this canvas',
+ 'canvas.share.failed': 'Couldn’t share. Try again.',
+ 'canvas.share.note': 'Newer versions stay private until you share them.',
+ 'canvas.share.open': 'Open share link',
+ 'canvas.share.privacy':
+ 'Anyone with the link can open this canvas. Before sharing, make sure it does not contain anything you would rather keep private, such as credentials, API keys, personal information, uploaded files, or images.',
+ 'canvas.share.publish': 'Share v{{version}}',
+ 'canvas.share.sharing': 'Sharing…',
+ 'canvas.share.success': 'Shared v{{version}}',
+ 'canvas.share.trigger': 'Share',
+ 'canvas.share.update': 'Update share to v{{version}}',
'canvas.title': 'Canvas',
'document.saveConflict': 'This document was updated elsewhere. Refreshing to the latest version.',
'document.todos.allCompleted': 'All tasks completed',
diff --git a/src/components/PublishConfirmModal/index.tsx b/src/components/PublishConfirmModal/index.tsx
index b7ef8518eed..2c89bd874cc 100644
--- a/src/components/PublishConfirmModal/index.tsx
+++ b/src/components/PublishConfirmModal/index.tsx
@@ -5,7 +5,15 @@ import { useTranslation } from 'react-i18next';
const CONFIRM_BODY_MAX_HEIGHT = 'min(52vh, 360px)';
-const PublishConfirmContent = ({ details, note }: { details?: ReactNode; note?: ReactNode }) => {
+const PublishConfirmContent = ({
+ details,
+ note,
+ privacy,
+}: {
+ details?: ReactNode;
+ note?: ReactNode;
+ privacy?: ReactNode;
+}) => {
const { t } = useTranslation('chat');
return (
@@ -16,7 +24,7 @@ const PublishConfirmContent = ({ details, note }: { details?: ReactNode; note?:
viewportProps={{ style: { height: 'auto', maxHeight: CONFIRM_BODY_MAX_HEIGHT } }}
>
<Flexbox gap={8} style={{ paddingBlock: 12, paddingInline: 16 }}>
- <Text>{t('workingPanel.localFile.publish.privacy')}</Text>
+ <Text>{privacy ?? t('workingPanel.localFile.publish.privacy')}</Text>
{details}
{note && <Text type={'secondary'}>{note}</Text>}
</Flexbox>
@@ -54,16 +62,27 @@ export interface PublishConfirmOptions {
note?: ReactNode;
okText: string;
onOk: () => void;
+ /** Replaces the default "anyone with the link" paragraph. */
+ privacy?: ReactNode;
+ /** Replaces the default publish-confirmation title. */
+ title?: ReactNode;
}
-export const openPublishConfirm = ({ details, note, okText, onOk }: PublishConfirmOptions) => {
+export const openPublishConfirm = ({
+ details,
+ note,
+ okText,
+ onOk,
+ privacy,
+ title,
+}: PublishConfirmOptions) => {
createModal({
- content: <PublishConfirmContent details={details} note={note} />,
+ content: <PublishConfirmContent details={details} note={note} privacy={privacy} />,
footer: <PublishConfirmFooter okText={okText} onOk={onOk} />,
styles: {
content: { minHeight: 0, overflow: 'hidden', padding: 0 },
},
- title: t('workingPanel.localFile.publish.confirmTitle', { ns: 'chat' }),
+ title: title ?? t('workingPanel.localFile.publish.confirmTitle', { ns: 'chat' }),
width: 420,
});
};
diff --git a/src/features/Conversation/WorkingSidebar/Canvas/CanvasPane.tsx b/src/features/Conversation/WorkingSidebar/Canvas/CanvasPane.tsx
index 91b5d4d1910..137146e2928 100644
--- a/src/features/Conversation/WorkingSidebar/Canvas/CanvasPane.tsx
+++ b/src/features/Conversation/WorkingSidebar/Canvas/CanvasPane.tsx
@@ -8,6 +8,7 @@ import { useTranslation } from 'react-i18next';
import PortalMoreMenu from '@/features/Portal/components/PortalMoreMenu';
import CanvasFrame from './CanvasFrame';
+import CanvasShareButton from './CanvasShareButton';
import { useCanvasMoreMenu } from './useCanvasMoreMenu';
import { useAwaitingCanvasSave, useCanvasTabView, useCanvasVersion } from './useCanvasVersion';
import { usePendingCanvasUpdate } from './usePendingCanvasUpdate';
@@ -103,6 +104,7 @@ const CanvasPane = memo<CanvasPaneProps>(({ canvasId }) => {
<Text ellipsis fontSize={12} style={{ flex: 1, minWidth: 0 }} type={'secondary'}>
{data.title}
</Text>
+ <CanvasShareButton data={data} onShared={() => mutate()} />
<PortalMoreMenu config={moreMenu} outdent={'end'} />
</Flexbox>
{showPending && (
diff --git a/src/features/Conversation/WorkingSidebar/Canvas/CanvasShareButton.tsx b/src/features/Conversation/WorkingSidebar/Canvas/CanvasShareButton.tsx
new file mode 100644
index 00000000000..f1ce3f76418
--- /dev/null
+++ b/src/features/Conversation/WorkingSidebar/Canvas/CanvasShareButton.tsx
@@ -0,0 +1,39 @@
+'use client';
+
+import { Button, DropdownMenu } from '@lobehub/ui';
+import { Share2 } from 'lucide-react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { type CanvasVersionDetail } from '@/services/canvas';
+
+import { useCanvasShareItems } from './useCanvasShareItems';
+
+interface CanvasShareButtonProps {
+ data: CanvasVersionDetail | null | undefined;
+ onShared: () => unknown;
+}
+
+/**
+ * The canvas toolbar's explicit share affordance. Publishing a canvas and
+ * opening its public link both live here, never in the `…` menu — sharing is
+ * the primary thing this toolbar offers, so it is a visible button.
+ */
+const CanvasShareButton = memo<CanvasShareButtonProps>(({ data, onShared }) => {
+ const { t } = useTranslation('portal');
+ const items = useCanvasShareItems(data, onShared);
+
+ if (items.length === 0) return null;
+
+ return (
+ <DropdownMenu items={items} placement={'bottomRight'}>
+ <Button icon={Share2} size={'small'} style={{ flex: 'none' }}>
+ {t('canvas.share.trigger')}
+ </Button>
+ </DropdownMenu>
+ );
+});
+
+CanvasShareButton.displayName = 'CanvasShareButton';
+
+export default CanvasShareButton;
diff --git a/src/features/Conversation/WorkingSidebar/Canvas/useCanvasMoreMenu.tsx b/src/features/Conversation/WorkingSidebar/Canvas/useCanvasMoreMenu.tsx
index 7872c3d885e..a6372d26684 100644
--- a/src/features/Conversation/WorkingSidebar/Canvas/useCanvasMoreMenu.tsx
+++ b/src/features/Conversation/WorkingSidebar/Canvas/useCanvasMoreMenu.tsx
@@ -5,7 +5,6 @@ import { type PortalMoreMenuConfig } from '@/features/Portal/components/PortalMo
import { type CanvasVersionDetail } from '@/services/canvas';
import { useChatStore } from '@/store/chat';
-import { useCanvasPublishItems } from './useCanvasPublishItems';
import { type CanvasTabView, useCanvasVersions } from './useCanvasVersion';
export const useCanvasMoreMenu = (
@@ -16,14 +15,15 @@ export const useCanvasMoreMenu = (
const { t } = useTranslation('portal');
const { data: versions } = useCanvasVersions(view.canvasId);
const openCanvas = useChatStore((s) => s.openCanvas);
- const publishItems = useCanvasPublishItems(data, refresh);
if (!data) return;
- const extraItems: DropdownItem[] = [...publishItems];
+ // Sharing is the toolbar's own button; the `…` menu only carries the
+ // utility actions and the version history.
+ const extraItems: DropdownItem[] = [];
if (versions && versions.length > 1) {
- extraItems.unshift({
+ extraItems.push({
children: versions.map((item) => ({
key: `v${item.version}`,
label: t('canvas.menu.versionItem', {
diff --git a/src/features/Conversation/WorkingSidebar/Canvas/useCanvasPublishItems.test.ts b/src/features/Conversation/WorkingSidebar/Canvas/useCanvasPublishItems.test.ts
deleted file mode 100644
index 1ebaa71f4f2..00000000000
--- a/src/features/Conversation/WorkingSidebar/Canvas/useCanvasPublishItems.test.ts
+++ /dev/null
@@ -1,75 +0,0 @@
-import { act, renderHook } from '@testing-library/react';
-import { beforeEach, describe, expect, it, vi } from 'vitest';
-
-import type { CanvasVersionDetail } from '@/services/canvas';
-
-import { useCanvasPublishItems } from './useCanvasPublishItems';
-
-const mocks = vi.hoisted(() => ({
- openPublishConfirm: vi.fn(),
- publish: vi.fn(),
- refreshAllConversations: vi.fn(),
-}));
-
-vi.mock('@/components/PublishConfirmModal', () => ({
- openPublishConfirm: mocks.openPublishConfirm,
-}));
-vi.mock('@/services/canvas', () => ({ canvasService: { publish: mocks.publish } }));
-vi.mock('@/services/work', () => ({
- workService: { refreshAllConversations: mocks.refreshAllConversations },
-}));
-
-const detail = (overrides: Partial<CanvasVersionDetail> = {}) =>
- ({
- canPublish: true,
- canvasId: 'cvs_1',
- latestVersion: 2,
- publishedUrl: null,
- publishedVersion: null,
- ...overrides,
- }) as unknown as CanvasVersionDetail;
-
-const clickPublish = (data: CanvasVersionDetail, onPublished = vi.fn()) => {
- const { result } = renderHook(() => useCanvasPublishItems(data, onPublished));
- const item = result.current.find((entry) => entry && 'key' in entry && entry.key === 'publish');
- act(() => {
- (item as { onClick: () => void }).onClick();
- });
-};
-
-beforeEach(() => {
- vi.clearAllMocks();
- mocks.publish.mockResolvedValue({ publishedVersion: 2 });
-});
-
-describe('useCanvasPublishItems', () => {
- it('asks for confirmation before a canvas becomes public', () => {
- clickPublish(detail());
-
- expect(mocks.publish).not.toHaveBeenCalled();
- expect(mocks.openPublishConfirm).toHaveBeenCalledWith(
- expect.objectContaining({ okText: 'canvas.menu.publish', note: 'canvas.publish.note' }),
- );
- });
-
- it('publishes once the confirmation is accepted', async () => {
- const onPublished = vi.fn();
- clickPublish(detail(), onPublished);
-
- await act(async () => {
- mocks.openPublishConfirm.mock.calls[0][0].onOk();
- });
-
- expect(mocks.publish).toHaveBeenCalledWith('cvs_1');
- expect(onPublished).toHaveBeenCalled();
- });
-
- it('confirms updating an existing public link as well', () => {
- clickPublish(detail({ publishedUrl: 'https://cost.lobehub.sites', publishedVersion: 1 }));
-
- expect(mocks.openPublishConfirm).toHaveBeenCalledWith(
- expect.objectContaining({ okText: 'canvas.menu.updatePublic' }),
- );
- expect(mocks.publish).not.toHaveBeenCalled();
- });
-});
diff --git a/src/features/Conversation/WorkingSidebar/Canvas/useCanvasPublishItems.ts b/src/features/Conversation/WorkingSidebar/Canvas/useCanvasPublishItems.ts
deleted file mode 100644
index 717c50ee189..00000000000
--- a/src/features/Conversation/WorkingSidebar/Canvas/useCanvasPublishItems.ts
+++ /dev/null
@@ -1,63 +0,0 @@
-import { type DropdownItem, toast } from '@lobehub/ui';
-import { useState } from 'react';
-import { useTranslation } from 'react-i18next';
-
-import { openPublishConfirm } from '@/components/PublishConfirmModal';
-import { canvasService, type CanvasVersionDetail } from '@/services/canvas';
-import { workService } from '@/services/work';
-
-export const useCanvasPublishItems = (
- data: CanvasVersionDetail | null | undefined,
- onPublished: () => unknown,
-): DropdownItem[] => {
- const { t } = useTranslation('portal');
- const [publishing, setPublishing] = useState(false);
-
- if (!data) return [];
-
- const items: DropdownItem[] = [];
- const publishedUrl = data.publishedUrl;
-
- if (publishedUrl) {
- items.push({
- key: 'open-public',
- label: t('canvas.menu.openPublic'),
- onClick: () => window.open(publishedUrl, '_blank', 'noopener,noreferrer'),
- });
- }
-
- if (data.canPublish && (publishing || data.publishedVersion !== data.latestVersion)) {
- const publish = async () => {
- setPublishing(true);
- try {
- const result = await canvasService.publish(data.canvasId);
- await onPublished();
- await workService.refreshAllConversations();
- toast.success(t('canvas.publish.success', { version: result.publishedVersion }));
- } catch (error) {
- console.error('[Canvas] publish failed', error);
- toast.error(t('canvas.publish.failed'));
- } finally {
- setPublishing(false);
- }
- };
-
- const publishLabel = t(publishedUrl ? 'canvas.menu.updatePublic' : 'canvas.menu.publish', {
- version: data.latestVersion,
- });
-
- items.push({
- disabled: publishing,
- key: 'publish',
- label: publishing ? t('canvas.menu.publishing') : publishLabel,
- onClick: () =>
- openPublishConfirm({
- note: t('canvas.publish.note'),
- okText: publishLabel,
- onOk: () => void publish(),
- }),
- });
- }
-
- return items;
-};
diff --git a/src/features/Conversation/WorkingSidebar/Canvas/useCanvasShareItems.test.ts b/src/features/Conversation/WorkingSidebar/Canvas/useCanvasShareItems.test.ts
new file mode 100644
index 00000000000..fcd81ab1586
--- /dev/null
+++ b/src/features/Conversation/WorkingSidebar/Canvas/useCanvasShareItems.test.ts
@@ -0,0 +1,101 @@
+import { act, renderHook } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import type { CanvasVersionDetail } from '@/services/canvas';
+
+import { useCanvasShareItems } from './useCanvasShareItems';
+
+const mocks = vi.hoisted(() => ({
+ openPublishConfirm: vi.fn(),
+ publish: vi.fn(),
+ refreshAllConversations: vi.fn(),
+}));
+
+vi.mock('@/components/PublishConfirmModal', () => ({
+ openPublishConfirm: mocks.openPublishConfirm,
+}));
+vi.mock('@/services/canvas', () => ({ canvasService: { publish: mocks.publish } }));
+vi.mock('@/services/work', () => ({
+ workService: { refreshAllConversations: mocks.refreshAllConversations },
+}));
+
+const detail = (overrides: Partial<CanvasVersionDetail> = {}) =>
+ ({
+ canPublish: true,
+ canvasId: 'cvs_1',
+ latestVersion: 2,
+ publishedUrl: null,
+ publishedVersion: null,
+ ...overrides,
+ }) as unknown as CanvasVersionDetail;
+
+const clickShare = (data: CanvasVersionDetail, onShared = vi.fn()) => {
+ const { result } = renderHook(() => useCanvasShareItems(data, onShared));
+ const item = result.current.find((entry) => 'key' in entry && entry.key === 'share');
+ if (!item || !('onClick' in item) || typeof item.onClick !== 'function') {
+ throw new Error('the share item was not offered');
+ }
+ act(() => {
+ item.onClick?.();
+ });
+};
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ mocks.publish.mockResolvedValue({ publishedVersion: 2 });
+});
+
+describe('useCanvasShareItems', () => {
+ it('asks for confirmation before a canvas becomes public', () => {
+ clickShare(detail());
+
+ expect(mocks.publish).not.toHaveBeenCalled();
+ expect(mocks.openPublishConfirm).toHaveBeenCalledWith(
+ expect.objectContaining({ okText: 'canvas.share.publish', note: 'canvas.share.note' }),
+ );
+ });
+
+ it('publishes once the confirmation is accepted', async () => {
+ const onShared = vi.fn();
+ clickShare(detail(), onShared);
+
+ await act(async () => {
+ mocks.openPublishConfirm.mock.calls[0][0].onOk();
+ });
+
+ expect(mocks.publish).toHaveBeenCalledWith('cvs_1');
+ expect(onShared).toHaveBeenCalled();
+ });
+
+ it('confirms updating an existing share as well', () => {
+ clickShare(detail({ publishedUrl: 'https://cost.lobehub.sites', publishedVersion: 1 }));
+
+ expect(mocks.openPublishConfirm).toHaveBeenCalledWith(
+ expect.objectContaining({ okText: 'canvas.share.update' }),
+ );
+ expect(mocks.publish).not.toHaveBeenCalled();
+ });
+
+ it('offers the share link only after the canvas is public', () => {
+ const { result: unshared } = renderHook(() => useCanvasShareItems(detail(), vi.fn()));
+ expect(unshared.current.some((item) => 'key' in item && item.key === 'open-public')).toBe(
+ false,
+ );
+
+ const { result: shared } = renderHook(() =>
+ useCanvasShareItems(
+ detail({ publishedUrl: 'https://cost.lobehub.sites', publishedVersion: 2 }),
+ vi.fn(),
+ ),
+ );
+ expect(shared.current.some((item) => 'key' in item && item.key === 'open-public')).toBe(true);
+ });
+
+ it('has nothing to offer for an unshared canvas the viewer cannot share', () => {
+ const { result } = renderHook(() =>
+ useCanvasShareItems(detail({ canPublish: false }), vi.fn()),
+ );
+
+ expect(result.current).toHaveLength(0);
+ });
+});
diff --git a/src/features/Conversation/WorkingSidebar/Canvas/useCanvasShareItems.ts b/src/features/Conversation/WorkingSidebar/Canvas/useCanvasShareItems.ts
new file mode 100644
index 00000000000..7e3d181245f
--- /dev/null
+++ b/src/features/Conversation/WorkingSidebar/Canvas/useCanvasShareItems.ts
@@ -0,0 +1,70 @@
+import { type DropdownItem, toast } from '@lobehub/ui';
+import { useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { openPublishConfirm } from '@/components/PublishConfirmModal';
+import { canvasService, type CanvasVersionDetail } from '@/services/canvas';
+import { workService } from '@/services/work';
+
+/**
+ * The canvas share actions. They live behind the toolbar's explicit `分享`
+ * button rather than the `…` menu: sharing a canvas is the one thing everyone
+ * looks for, so it gets its own affordance.
+ */
+export const useCanvasShareItems = (
+ data: CanvasVersionDetail | null | undefined,
+ onShared: () => unknown,
+): DropdownItem[] => {
+ const { t } = useTranslation('portal');
+ const [sharing, setSharing] = useState(false);
+
+ if (!data) return [];
+
+ const items: DropdownItem[] = [];
+ const publishedUrl = data.publishedUrl;
+
+ if (data.canPublish && (sharing || data.publishedVersion !== data.latestVersion)) {
+ const share = async () => {
+ setSharing(true);
+ try {
+ const result = await canvasService.publish(data.canvasId);
+ await onShared();
+ await workService.refreshAllConversations();
+ toast.success(t('canvas.share.success', { version: result.publishedVersion }));
+ } catch (error) {
+ console.error('[Canvas] share failed', error);
+ toast.error(t('canvas.share.failed'));
+ } finally {
+ setSharing(false);
+ }
+ };
+
+ const shareLabel = t(publishedUrl ? 'canvas.share.update' : 'canvas.share.publish', {
+ version: data.latestVersion,
+ });
+
+ items.push({
+ disabled: sharing,
+ key: 'share',
+ label: sharing ? t('canvas.share.sharing') : shareLabel,
+ onClick: () =>
+ openPublishConfirm({
+ note: t('canvas.share.note'),
+ okText: shareLabel,
+ onOk: () => void share(),
+ privacy: t('canvas.share.privacy'),
+ title: t('canvas.share.confirmTitle'),
+ }),
+ });
+ }
+
+ if (publishedUrl) {
+ items.push({
+ key: 'open-public',
+ label: t('canvas.share.open'),
+ onClick: () => window.open(publishedUrl, '_blank', 'noopener,noreferrer'),
+ });
+ }
+
+ return items;
+};
diff --git a/src/features/Work/CanvasWorkCard.tsx b/src/features/Work/CanvasWorkCard.tsx
index c4b38bb4012..1df73c3c576 100644
--- a/src/features/Work/CanvasWorkCard.tsx
+++ b/src/features/Work/CanvasWorkCard.tsx
@@ -38,7 +38,6 @@ const styles = stylex.create({
borderRadius: cssVar.borderRadiusLG,
borderStyle: 'solid',
borderWidth: 1,
- maxWidth: 480,
overflow: 'hidden',
width: '100%',
},
@@ -119,7 +118,7 @@ const CanvasWorkCard = memo<CanvasWorkCardProps>(({ className, item, onOpen }) =
</Text>
{item.url && (
<Tag color={'blue'} size={'small'}>
- {t('workingPanel.works.canvasPublished')}
+ {t('workingPanel.works.canvasShared')}
</Tag>
)}
</Flexbox>