🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat: add always show tools render in createPlan & createDoc tools (#10937)
Shinji-Lic2249513400d
diff --git a/locales/zh-CN/file.json b/locales/zh-CN/file.jsonindex 490011e59df..0d6f35d4131 100644--- a/locales/zh-CN/file.json+++ b/locales/zh-CN/file.json@@ -96,6 +96,7 @@"pageList.selectNote": "选择一个文稿开始编辑","pageList.title": "文稿","pageList.untitled": "无标题",+ "portal.openInPageEditor": "在文稿中编辑","preview.downloadFile": "下载文件","preview.unsupportedFileAndContact": "此文件格式暂不支持在线预览,如有预览诉求,欢迎<1>反馈给我们</1>","searchFilePlaceholder": "搜索文件",diff --git a/packages/builtin-tool-gtd/src/manifest.ts b/packages/builtin-tool-gtd/src/manifest.tsindex 43383d19091..ce08ddeb088 100644--- a/packages/builtin-tool-gtd/src/manifest.ts+++ b/packages/builtin-tool-gtd/src/manifest.ts@@ -14,7 +14,7 @@ export const GTDManifest: BuiltinToolManifest = {'Create a high-level plan document. Plans define the strategic direction (the "what" and "why"), while todos handle the actionable steps.',name: GTDApiName.createPlan,humanIntervention: 'always',- renderDisplayControl: 'expand',+ renderDisplayControl: 'alwaysExpand',parameters: {properties: {goal: {diff --git a/packages/builtin-tool-notebook/src/manifest.ts b/packages/builtin-tool-notebook/src/manifest.tsindex e3b20f27130..4529c8861d4 100644--- a/packages/builtin-tool-notebook/src/manifest.ts+++ b/packages/builtin-tool-notebook/src/manifest.ts@@ -33,6 +33,7 @@ export const NotebookManifest: BuiltinToolManifest = {required: ['title', 'description', 'content'],type: 'object',},+ renderDisplayControl: 'alwaysExpand',},{description:diff --git a/src/app/[variants]/(main)/chat/features/Portal/_layout/Desktop.tsx b/src/app/[variants]/(main)/chat/features/Portal/_layout/Desktop.tsxindex 0ed3cd25979..fb6bc84bd1c 100644--- a/src/app/[variants]/(main)/chat/features/Portal/_layout/Desktop.tsx+++ b/src/app/[variants]/(main)/chat/features/Portal/_layout/Desktop.tsx@@ -1,15 +1,10 @@-import { PropsWithChildren } from 'react';--import { PortalHeader } from '@/features/Portal/router';+import { PortalContent } from '@/features/Portal/router';import Body from '../features/Body';-const Layout = ({ children }: PropsWithChildren) => {+const Layout = () => {return (- <>- <PortalHeader />- <Body>{children}</Body>- </>+ <PortalContent renderBody={(body) => <Body>{body}</Body>} />);};diff --git a/src/app/[variants]/(main)/chat/features/Portal/_layout/Mobile.tsx b/src/app/[variants]/(main)/chat/features/Portal/_layout/Mobile.tsxindex f56ab2f1a67..112d469e993 100644--- a/src/app/[variants]/(main)/chat/features/Portal/_layout/Mobile.tsx+++ b/src/app/[variants]/(main)/chat/features/Portal/_layout/Mobile.tsx@@ -2,10 +2,10 @@import { Flexbox, Modal } from '@lobehub/ui';import { createStyles } from 'antd-style';-import { PropsWithChildren } from 'react';+import { ReactNode } from 'react';import { useTranslation } from 'react-i18next';-import { PortalHeader } from '@/features/Portal/router';+import { PortalContent } from '@/features/Portal/router';import { useChatStore } from '@/store/chat';const useStyles = createStyles(({ css, token }) => ({@@ -14,7 +14,7 @@ const useStyles = createStyles(({ css, token }) => ({`,}));-const Layout = ({ children }: PropsWithChildren) => {+const Layout = () => {const { styles, cx } = useStyles();const [showMobilePortal, isPortalThread, togglePortal] = useChatStore((s) => [s.showPortal,@@ -23,6 +23,23 @@ const Layout = ({ children }: PropsWithChildren) => {]);const { t } = useTranslation('portal');+ const renderBody = (body: ReactNode) => (+ <Flexbox+ gap={8}+ height={'calc(100% - 52px)'}+ padding={'0 8px'}+ style={{ overflow: 'hidden' }}+ >+ <Flexbox+ height={'100%'}+ style={{ marginInline: -8, overflow: 'hidden', position: 'relative' }}+ width={'calc(100% + 16px)'}+ >+ {body}+ </Flexbox>+ </Flexbox>+ );+return (<ModalallowFullscreen@@ -37,21 +54,7 @@ const Layout = ({ children }: PropsWithChildren) => {}}title={t('title')}>- <PortalHeader />- <Flexbox- gap={8}- height={'calc(100% - 52px)'}- padding={'0 8px'}- style={{ overflow: 'hidden' }}- >- <Flexbox- height={'100%'}- style={{ marginInline: -8, overflow: 'hidden', position: 'relative' }}- width={'calc(100% + 16px)'}- >- {children}- </Flexbox>- </Flexbox>+ <PortalContent renderBody={renderBody} /></Modal>);};diff --git a/src/app/[variants]/(main)/chat/features/Portal/features/PortalPanel.tsx b/src/app/[variants]/(main)/chat/features/Portal/features/PortalPanel.tsxindex 9080a2ef4e2..6c238ad4a9a 100644--- a/src/app/[variants]/(main)/chat/features/Portal/features/PortalPanel.tsx+++ b/src/app/[variants]/(main)/chat/features/Portal/features/PortalPanel.tsx@@ -1,11 +1,9 @@-import { Suspense, lazy, memo } from 'react';+import { Suspense, memo } from 'react';import DesktopLayout from '@/app/[variants]/(main)/chat/features/Portal/_layout/Desktop';import MobileLayout from '@/app/[variants]/(main)/chat/features/Portal/_layout/Mobile';import Loading from '@/components/Loading/BrandTextLoading';-const PortalBody = lazy(() => import('@/features/Portal/router'));-interface PortalPanelProps {mobile?: boolean;}@@ -15,9 +13,7 @@ const PortalPanel = memo<PortalPanelProps>(({ mobile }) => {return (<Suspense fallback={<Loading debugId="PortalPanel" />}>- <Layout>- <PortalBody />- </Layout>+ <Layout /></Suspense>);});diff --git a/src/app/[variants]/(main)/group/features/Portal/_layout/Desktop.tsx b/src/app/[variants]/(main)/group/features/Portal/_layout/Desktop.tsxindex 0ed3cd25979..fb6bc84bd1c 100644--- a/src/app/[variants]/(main)/group/features/Portal/_layout/Desktop.tsx+++ b/src/app/[variants]/(main)/group/features/Portal/_layout/Desktop.tsx@@ -1,15 +1,10 @@-import { PropsWithChildren } from 'react';--import { PortalHeader } from '@/features/Portal/router';+import { PortalContent } from '@/features/Portal/router';import Body from '../features/Body';-const Layout = ({ children }: PropsWithChildren) => {+const Layout = () => {return (- <>- <PortalHeader />- <Body>{children}</Body>- </>+ <PortalContent renderBody={(body) => <Body>{body}</Body>} />);};diff --git a/src/app/[variants]/(main)/group/features/Portal/_layout/Mobile.tsx b/src/app/[variants]/(main)/group/features/Portal/_layout/Mobile.tsxindex f56ab2f1a67..112d469e993 100644--- a/src/app/[variants]/(main)/group/features/Portal/_layout/Mobile.tsx+++ b/src/app/[variants]/(main)/group/features/Portal/_layout/Mobile.tsx@@ -2,10 +2,10 @@import { Flexbox, Modal } from '@lobehub/ui';import { createStyles } from 'antd-style';-import { PropsWithChildren } from 'react';+import { ReactNode } from 'react';import { useTranslation } from 'react-i18next';-import { PortalHeader } from '@/features/Portal/router';+import { PortalContent } from '@/features/Portal/router';import { useChatStore } from '@/store/chat';const useStyles = createStyles(({ css, token }) => ({@@ -14,7 +14,7 @@ const useStyles = createStyles(({ css, token }) => ({`,}));-const Layout = ({ children }: PropsWithChildren) => {+const Layout = () => {const { styles, cx } = useStyles();const [showMobilePortal, isPortalThread, togglePortal] = useChatStore((s) => [s.showPortal,@@ -23,6 +23,23 @@ const Layout = ({ children }: PropsWithChildren) => {]);const { t } = useTranslation('portal');+ const renderBody = (body: ReactNode) => (+ <Flexbox+ gap={8}+ height={'calc(100% - 52px)'}+ padding={'0 8px'}+ style={{ overflow: 'hidden' }}+ >+ <Flexbox+ height={'100%'}+ style={{ marginInline: -8, overflow: 'hidden', position: 'relative' }}+ width={'calc(100% + 16px)'}+ >+ {body}+ </Flexbox>+ </Flexbox>+ );+return (<ModalallowFullscreen@@ -37,21 +54,7 @@ const Layout = ({ children }: PropsWithChildren) => {}}title={t('title')}>- <PortalHeader />- <Flexbox- gap={8}- height={'calc(100% - 52px)'}- padding={'0 8px'}- style={{ overflow: 'hidden' }}- >- <Flexbox- height={'100%'}- style={{ marginInline: -8, overflow: 'hidden', position: 'relative' }}- width={'calc(100% + 16px)'}- >- {children}- </Flexbox>- </Flexbox>+ <PortalContent renderBody={renderBody} /></Modal>);};diff --git a/src/app/[variants]/(main)/group/features/Portal/features/PortalPanel.tsx b/src/app/[variants]/(main)/group/features/Portal/features/PortalPanel.tsxindex 9080a2ef4e2..34ae9ef3cbc 100644--- a/src/app/[variants]/(main)/group/features/Portal/features/PortalPanel.tsx+++ b/src/app/[variants]/(main)/group/features/Portal/features/PortalPanel.tsx@@ -1,11 +1,9 @@-import { Suspense, lazy, memo } from 'react';+import { Suspense, memo } from 'react';-import DesktopLayout from '@/app/[variants]/(main)/chat/features/Portal/_layout/Desktop';-import MobileLayout from '@/app/[variants]/(main)/chat/features/Portal/_layout/Mobile';+import DesktopLayout from '@/app/[variants]/(main)/group/features/Portal/_layout/Desktop';+import MobileLayout from '@/app/[variants]/(main)/group/features/Portal/_layout/Mobile';import Loading from '@/components/Loading/BrandTextLoading';-const PortalBody = lazy(() => import('@/features/Portal/router'));-interface PortalPanelProps {mobile?: boolean;}@@ -15,9 +13,7 @@ const PortalPanel = memo<PortalPanelProps>(({ mobile }) => {return (<Suspense fallback={<Loading debugId="PortalPanel" />}>- <Layout>- <PortalBody />- </Layout>+ <Layout /></Suspense>);});diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsxindex 13df5d473d3..fc302789775 100644--- a/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx@@ -29,6 +29,11 @@ export interface GroupToolProps {id: string;identifier: string;intervention?: ToolIntervention;+ /**+ * Callback to register whether this tool can be collapsed+ * Used by parent Accordion to prevent collapsing when alwaysExpand is set+ */+ onCollapsibleChange?: (canCollapse: boolean) => void;result?: ChatToolResult;toolMessageId?: string;type?: string;@@ -42,6 +47,7 @@ const Tool = memo<GroupToolProps>(id,intervention,identifier,+ onCollapsibleChange,result,type,toolMessageId,@@ -58,21 +64,36 @@ const Tool = memo<GroupToolProps>(const isReject = intervention?.status === 'rejected';const isAbort = intervention?.status === 'aborted';const needExpand = renderDisplayControl !== 'collapsed' || isPending;+ const isAlwaysExpand = renderDisplayControl === 'alwaysExpand';const showCustomPluginRender = !isPending && !isReject && !isAbort;+ // Wrap handleExpand to prevent collapsing when alwaysExpand is set+ const wrappedHandleExpand = (expand?: boolean) => {+ // Block collapse action when alwaysExpand is set+ if (isAlwaysExpand && expand === false) {+ return;+ }+ handleExpand?.(expand);+ };+useEffect(() => {if (needExpand) {- setTimeout(() => handleExpand?.(true), 100);+ setTimeout(() => wrappedHandleExpand(true), 100);}}, [needExpand]);+ // Notify parent about collapsibility+ useEffect(() => {+ onCollapsibleChange?.(!isAlwaysExpand);+ }, [isAlwaysExpand, onCollapsibleChange]);+return (<AccordionItemaction={<ActionsassistantMessageId={assistantMessageId}- handleExpand={handleExpand}+ handleExpand={wrappedHandleExpand}identifier={identifier}setShowDebug={setShowDebug}setShowPluginRender={setShowPluginRender}diff --git a/src/features/Conversation/Messages/AssistantGroup/Tools.tsx b/src/features/Conversation/Messages/AssistantGroup/Tools.tsxindex 09b0359fbb6..7d163059e3d 100644--- a/src/features/Conversation/Messages/AssistantGroup/Tools.tsx+++ b/src/features/Conversation/Messages/AssistantGroup/Tools.tsx@@ -1,6 +1,6 @@import { ChatToolPayloadWithResult } from '@lobechat/types';import { Accordion } from '@lobehub/ui';-import { type Key, memo, useState } from 'react';+import { type Key, memo, useCallback, useRef, useState } from 'react';import Tool from './Tool';@@ -11,15 +11,29 @@ interface ToolsRendererProps {export const Tools = memo<ToolsRendererProps>(({ messageId, tools }) => {const [showToolContents, setShowToolDetails] = useState<Key[]>([]);+ // Track which tools cannot be collapsed (alwaysExpand)+ const nonCollapsibleToolsRef = useRef<Set<string>>(new Set());++ const handleExpandedChange = useCallback((keys: Key[]) => {+ setShowToolDetails((prev) => {+ // Ensure non-collapsible tools stay expanded+ const newKeys = new Set(keys);+ for (const toolId of nonCollapsibleToolsRef.current) {+ newKeys.add(toolId);+ }+ // Only update if different from previous+ const newKeysArray = [...newKeys];+ if (newKeysArray.length === prev.length && newKeysArray.every((k) => prev.includes(k))) {+ return prev;+ }+ return newKeysArray;+ });+ }, []);if (!tools || tools.length === 0) return null;return (- <Accordion- expandedKeys={showToolContents}- gap={8}- onExpandedChange={(keys) => setShowToolDetails(keys)}- >+ <Accordion expandedKeys={showToolContents} gap={8} onExpandedChange={handleExpandedChange}>{tools.map((tool) => {return (<Tool@@ -44,6 +58,13 @@ export const Tools = memo<ToolsRendererProps>(({ messageId, tools }) => {identifier={tool.identifier}intervention={tool.intervention}key={tool.id}+ onCollapsibleChange={(canCollapse) => {+ if (canCollapse) {+ nonCollapsibleToolsRef.current.delete(tool.id);+ } else {+ nonCollapsibleToolsRef.current.add(tool.id);+ }+ }}result={tool.result}toolMessageId={tool.result_msg_id}type={tool.type}diff --git a/src/features/Portal/Document/AutoSaveHint.tsx b/src/features/Portal/Document/AutoSaveHint.tsxnew file mode 100644index 00000000000..90e8460437b--- /dev/null+++ b/src/features/Portal/Document/AutoSaveHint.tsx@@ -0,0 +1,16 @@+'use client';++import { memo } from 'react';++import AutoSaveHintBase from '@/components/Editor/AutoSaveHint';++import { useDocumentEditorStore } from './store';++const AutoSaveHint = memo(() => {+ const saveStatus = useDocumentEditorStore((s) => s.saveStatus);+ const lastUpdatedTime = useDocumentEditorStore((s) => s.lastUpdatedTime);++ return <AutoSaveHintBase lastUpdatedTime={lastUpdatedTime} saveStatus={saveStatus} />;+});++export default AutoSaveHint;diff --git a/src/features/Portal/Document/Body.tsx b/src/features/Portal/Document/Body.tsxindex d025e90e9d5..10badb6fd69 100644--- a/src/features/Portal/Document/Body.tsx+++ b/src/features/Portal/Document/Body.tsx@@ -4,11 +4,8 @@ import { Flexbox } from '@lobehub/ui';import { createStyles } from 'antd-style';import { memo } from 'react';-import { useChatStore } from '@/store/chat';-import { chatPortalSelectors } from '@/store/chat/selectors';--import { DocumentEditorProvider } from './DocumentEditorProvider';import EditorCanvas from './EditorCanvas';+import Title from './Title';const useStyles = createStyles(({ css }) => ({content: css`@@ -21,21 +18,13 @@ const useStyles = createStyles(({ css }) => ({const DocumentBody = memo(() => {const { styles } = useStyles();- const [topicId, documentId] = useChatStore((s) => [- s.activeTopicId,- chatPortalSelectors.portalDocumentId(s),- ]);-- if (!documentId) return null;-return (- <DocumentEditorProvider documentId={documentId} topicId={topicId}>- <Flexbox flex={1} height={'100%'} style={{ overflow: 'hidden' }}>- <div className={styles.content}>- <EditorCanvas />- </div>- </Flexbox>- </DocumentEditorProvider>+ <Flexbox flex={1} height={'100%'} style={{ overflow: 'hidden' }}>+ <div className={styles.content}>+ <Title />+ <EditorCanvas />+ </div>+ </Flexbox>);});diff --git a/src/features/Portal/Document/EditorCanvas.tsx b/src/features/Portal/Document/EditorCanvas.tsxindex 2411d95e2e5..3490a95ee12 100644--- a/src/features/Portal/Document/EditorCanvas.tsx+++ b/src/features/Portal/Document/EditorCanvas.tsx@@ -4,6 +4,7 @@ import {ReactCodePlugin,ReactCodeblockPlugin,ReactHRPlugin,+ ReactImagePlugin,ReactLinkPlugin,ReactListPlugin,ReactMathPlugin,@@ -44,6 +45,9 @@ const EditorCanvas = memo(() => {ReactLinkPlugin,ReactTablePlugin,ReactMathPlugin,+ Editor.withProps(ReactImagePlugin, {+ defaultBlockImage: true,+ }),]}style={{paddingBottom: 64,diff --git a/src/features/Portal/Document/Header.tsx b/src/features/Portal/Document/Header.tsxindex bd42d6da021..dba0bcef914 100644--- a/src/features/Portal/Document/Header.tsx+++ b/src/features/Portal/Document/Header.tsx@@ -1,16 +1,26 @@'use client';-import { ActionIcon, Flexbox, Text } from '@lobehub/ui';+import { ActionIcon, Button, Flexbox, Text } from '@lobehub/ui';import { cx } from 'antd-style';-import { ArrowLeft } from 'lucide-react';+import { ArrowLeft, ExternalLink } from 'lucide-react';+import { useState } from 'react';+import { useTranslation } from 'react-i18next';+import { useNavigate } from 'react-router-dom';+import { documentService } from '@/services/document';import { useChatStore } from '@/store/chat';import { chatPortalSelectors } from '@/store/chat/selectors';import { useNotebookStore } from '@/store/notebook';import { notebookSelectors } from '@/store/notebook/selectors';import { oneLineEllipsis } from '@/styles';+import AutoSaveHint from './AutoSaveHint';+const Header = () => {+ const { t } = useTranslation('file');+ const navigate = useNavigate();+ const [loading, setLoading] = useState(false);+const [topicId, documentId, closeDocument] = useChatStore((s) => [s.activeTopicId,chatPortalSelectors.portalDocumentId(s),@@ -19,6 +29,25 @@ const Header = () => {const document = useNotebookStore(notebookSelectors.getDocumentById(topicId, documentId));+ const handleOpenInPageEditor = async () => {+ if (!documentId) return;++ setLoading(true);+ try {+ // Update fileType to custom/document so it appears in page list+ await documentService.updateDocument({+ fileType: 'custom/document',+ id: documentId,+ });++ // Navigate to the page editor+ // Note: /page route automatically adds 'docs_' prefix to the id+ navigate(`/page/${documentId.replace(/^docs_/, '')}`);+ } finally {+ setLoading(false);+ }+ };+if (!document) return null;return (@@ -29,6 +58,18 @@ const Header = () => {{document.title}</Text></Flexbox>+ <Flexbox align={'center'} gap={8} horizontal>+ <AutoSaveHint />+ <Button+ icon={<ExternalLink size={14} />}+ loading={loading}+ onClick={handleOpenInPageEditor}+ size={'small'}+ type={'text'}+ >+ {t('portal.openInPageEditor')}+ </Button>+ </Flexbox></Flexbox>);};diff --git a/src/features/Portal/Document/StoreUpdater.tsx b/src/features/Portal/Document/StoreUpdater.tsxindex d729f2607bf..142358f054f 100644--- a/src/features/Portal/Document/StoreUpdater.tsx+++ b/src/features/Portal/Document/StoreUpdater.tsx@@ -48,17 +48,16 @@ const StoreUpdater = memo<StoreUpdaterProps>(({ documentId, topicId }) => {try {log('Loading content for document:', documentId);- if (document.content) {- editor.setDocument('markdown', document.content);- storeApi.setState({- lastSavedContent: document.content,- });- } else {- editor.setDocument('markdown', ' ');- storeApi.setState({- lastSavedContent: '',- });- }+ const content = document.content || '';++ // Set state before setDocument to ensure lastSavedContent is correct+ // when handleContentChange is triggered+ storeApi.setState({+ currentTitle: document.title || '',+ lastSavedContent: content,+ });++ editor.setDocument('markdown', content || ' ');lastLoadedDocIdRef.current = documentId;setContentInit(true);diff --git a/src/features/Portal/Document/Title.tsx b/src/features/Portal/Document/Title.tsxnew file mode 100644index 00000000000..39a67374fdd--- /dev/null+++ b/src/features/Portal/Document/Title.tsx@@ -0,0 +1,54 @@+'use client';++import { Flexbox, TextArea } from '@lobehub/ui';+import { memo } from 'react';+import { useTranslation } from 'react-i18next';++import { useDocumentEditorStore } from './store';++const Title = memo(() => {+ const { t } = useTranslation('file');++ const currentTitle = useDocumentEditorStore((s) => s.currentTitle);+ const setCurrentTitle = useDocumentEditorStore((s) => s.setCurrentTitle);+ const handleTitleSubmit = useDocumentEditorStore((s) => s.handleTitleSubmit);++ return (+ <Flexbox+ gap={16}+ onClick={(e) => {+ e.stopPropagation();+ e.preventDefault();+ }}+ paddingBlock={16}+ style={{+ cursor: 'default',+ }}+ >+ <TextArea+ autoSize={{ minRows: 1 }}+ onChange={(e) => {+ setCurrentTitle(e.target.value);+ }}+ onKeyDown={(e) => {+ if (e.key === 'Enter') {+ e.preventDefault();+ handleTitleSubmit();+ }+ }}+ placeholder={t('pageEditor.titlePlaceholder')}+ style={{+ fontSize: 24,+ fontWeight: 600,+ padding: 0,+ resize: 'none',+ width: '100%',+ }}+ value={currentTitle}+ variant={'borderless'}+ />+ </Flexbox>+ );+});++export default Title;diff --git a/src/features/Portal/Document/Wrapper.tsx b/src/features/Portal/Document/Wrapper.tsxnew file mode 100644index 00000000000..dc411caa763--- /dev/null+++ b/src/features/Portal/Document/Wrapper.tsx@@ -0,0 +1,25 @@+'use client';++import { PropsWithChildren, memo } from 'react';++import { useChatStore } from '@/store/chat';+import { chatPortalSelectors } from '@/store/chat/selectors';++import { DocumentEditorProvider } from './DocumentEditorProvider';++const Wrapper = memo<PropsWithChildren>(({ children }) => {+ const [topicId, documentId] = useChatStore((s) => [+ s.activeTopicId,+ chatPortalSelectors.portalDocumentId(s),+ ]);++ if (!documentId) return null;++ return (+ <DocumentEditorProvider documentId={documentId} topicId={topicId}>+ {children}+ </DocumentEditorProvider>+ );+});++export default Wrapper;diff --git a/src/features/Portal/Document/index.ts b/src/features/Portal/Document/index.tsindex b4fd8d325ce..d4d02f14709 100644--- a/src/features/Portal/Document/index.ts+++ b/src/features/Portal/Document/index.ts@@ -2,9 +2,11 @@ import { PortalImpl } from '../type';import Body from './Body';import Header from './Header';import { useEnable } from './useEnable';+import Wrapper from './Wrapper';export const Document: PortalImpl = {Body,Title: Header,+ Wrapper,useEnable,};diff --git a/src/features/Portal/Document/store/action.ts b/src/features/Portal/Document/store/action.tsindex d12e260fd6b..ff878bfc542 100644--- a/src/features/Portal/Document/store/action.ts+++ b/src/features/Portal/Document/store/action.ts@@ -14,7 +14,9 @@ const log = debug('portal:document-editor');export interface DocumentEditorAction {flushSave: () => void;handleContentChange: () => void;+ handleTitleSubmit: () => Promise<void>;performSave: () => Promise<void>;+ setCurrentTitle: (title: string) => void;}export type DocumentEditorStore = DocumentEditorState & DocumentEditorAction;@@ -63,8 +65,14 @@ export const createDocumentEditorStore: (}},+ handleTitleSubmit: async () => {+ const { performSave, editor } = get();+ await performSave();+ editor?.focus();+ },+performSave: async () => {- const { editor, documentId, topicId, isDirty } = get();+ const { editor, documentId, topicId, isDirty, currentTitle } = get();if (!editor || !documentId || !topicId) return;@@ -79,6 +87,7 @@ export const createDocumentEditorStore: ({content: currentContent,id: documentId,+ title: currentTitle || undefined,},topicId,);@@ -86,6 +95,7 @@ export const createDocumentEditorStore: (set({isDirty: false,lastSavedContent: currentContent,+ lastUpdatedTime: new Date(),saveStatus: 'saved',});@@ -95,5 +105,10 @@ export const createDocumentEditorStore: (set({ saveStatus: 'idle' });}},++ setCurrentTitle: (title: string) => {+ set({ currentTitle: title, isDirty: true });+ debouncedSave();+ },};};diff --git a/src/features/Portal/Document/store/initialState.ts b/src/features/Portal/Document/store/initialState.tsindex 3389de95775..fe210485f94 100644--- a/src/features/Portal/Document/store/initialState.ts+++ b/src/features/Portal/Document/store/initialState.ts@@ -3,18 +3,22 @@import { IEditor } from '@lobehub/editor';export interface DocumentEditorState {+ currentTitle: string;documentId: string | undefined;editor?: IEditor;isDirty: boolean;lastSavedContent: string;+ lastUpdatedTime: Date | null;saveStatus: 'idle' | 'saving' | 'saved';topicId: string | undefined;}export const initialDocumentEditorState: DocumentEditorState = {+ currentTitle: '',documentId: undefined,isDirty: false,lastSavedContent: '',+ lastUpdatedTime: null,saveStatus: 'idle',topicId: undefined,};diff --git a/src/features/Portal/router.tsx b/src/features/Portal/router.tsxindex c5e029c5cf5..ca5f4f27d3d 100644--- a/src/features/Portal/router.tsx+++ b/src/features/Portal/router.tsx@@ -1,6 +1,6 @@'use client';-import { memo } from 'react';+import React, { Fragment, memo } from 'react';import { Artifacts } from './Artifacts';import { Document } from './Document';@@ -81,4 +81,52 @@ const PortalBody = memo(() => {return <HomeBody />;});+interface PortalContentProps {+ renderBody?: (body: React.ReactNode) => React.ReactNode;+}++/**+ * Portal content with Wrapper support+ * When an enabled item has a Wrapper, it wraps both Header and Body+ */+const PortalContent = memo<PortalContentProps>(({ renderBody }) => {+ const enabledList: boolean[] = [];++ for (const item of items) {+ const enabled = item.useEnable();+ enabledList.push(enabled);+ }++ // Find the first enabled item+ let enabledIndex = -1;+ for (const [i, element] of enabledList.entries()) {+ if (element) {+ enabledIndex = i;+ break;+ }+ }++ // Get components for the enabled item+ const enabledItem = enabledIndex >= 0 ? items[enabledIndex] : null;+ const Wrapper = enabledItem?.Wrapper || Fragment;+ const CustomHeader = enabledItem?.Header;+ const Body = enabledItem?.Body || HomeBody;++ const headerContent = CustomHeader ? (+ <CustomHeader />+ ) : (+ <Header title={enabledItem?.Title ? <enabledItem.Title /> : <HomeTitle />} />+ );++ const bodyContent = <Body />;++ return (+ <Wrapper>+ {headerContent}+ {renderBody ? renderBody(bodyContent) : bodyContent}+ </Wrapper>+ );+});++export { PortalContent };export default PortalBody;diff --git a/src/features/Portal/type.ts b/src/features/Portal/type.tsindex 32d7cdd2764..58b6dd2ada7 100644--- a/src/features/Portal/type.ts+++ b/src/features/Portal/type.ts@@ -1,9 +1,10 @@-import { FC } from 'react';+import { FC, PropsWithChildren } from 'react';export interface PortalImpl {Body: FC;Header?: FC;Title: FC;+ Wrapper?: FC<PropsWithChildren>;onClose?: () => void;useEnable: () => boolean;}diff --git a/src/locales/default/file.ts b/src/locales/default/file.tsindex 3a7f84f37f3..a7183516802 100644--- a/src/locales/default/file.ts+++ b/src/locales/default/file.ts@@ -96,6 +96,7 @@ export default {"pageList.selectNote": "Select a page to start editing","pageList.title": "Pages","pageList.untitled": "Untitled",+ "portal.openInPageEditor": "Edit in Page","preview.downloadFile": "Download File","preview.unsupportedFileAndContact": "This file format is not currently supported for online preview. If you have a request for previewing, feel free to <1>contact us</1>.","searchFilePlaceholder": "Search Files",diff --git a/src/server/routers/lambda/document.ts b/src/server/routers/lambda/document.tsindex 3dd3115a83d..8adde853838 100644--- a/src/server/routers/lambda/document.ts+++ b/src/server/routers/lambda/document.ts@@ -131,6 +131,7 @@ export const documentRouter = router({z.object({content: z.string().optional(),editorData: z.string().optional(),+ fileType: z.string().optional(),id: z.string(),metadata: z.record(z.any()).optional(),parentId: z.string().nullable().optional(),diff --git a/src/server/services/document/index.ts b/src/server/services/document/index.tsindex 5ebf3c4ba43..e8481f45991 100644--- a/src/server/services/document/index.ts+++ b/src/server/services/document/index.ts@@ -172,6 +172,7 @@ export class DocumentService {params: {content?: string;editorData?: Record<string, any>;+ fileType?: string;metadata?: Record<string, any>;parentId?: string | null;title?: string;@@ -189,6 +190,10 @@ export class DocumentService {updates.editorData = params.editorData;}+ if (params.fileType !== undefined) {+ updates.fileType = params.fileType;+ }+if (params.title !== undefined) {updates.title = params.title;updates.filename = params.title;diff --git a/src/services/document/index.ts b/src/services/document/index.tsindex 97e578b615a..baf715785f9 100644--- a/src/services/document/index.ts+++ b/src/services/document/index.ts@@ -16,6 +16,7 @@ export interface CreateDocumentParams {export interface UpdateDocumentParams {content?: string;editorData?: string;+ fileType?: string;id: string;metadata?: Record<string, any>;parentId?: string | null;