🤯 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
🐛 fix(page-editor): restore table bleed and keep inline dollar text plain (#18340)
Arvin Xu024adbe843e3
diff --git a/apps/server/src/services/agentDocuments/headlessEditor.test.ts b/apps/server/src/services/agentDocuments/headlessEditor.test.tsindex 7d7a96fbb0e..88baea5c4a1 100644--- a/apps/server/src/services/agentDocuments/headlessEditor.test.ts+++ b/apps/server/src/services/agentDocuments/headlessEditor.test.ts@@ -38,6 +38,16 @@ describe('agent document headless editor', () => {expect(isValidEditorData(snapshot.editorData)).toBe(true);});+ it('should keep inline dollar text as plain text while preserving block math', async () => {+ const snapshot = await createMarkdownEditorSnapshot(+ 'Budget variable: $x$ and $100k\n\n$$\nE = mc^2\n$$',+ );++ expect(snapshot.content).toContain('Budget variable: $x$ and $100k');+ expect(hasNodeType(snapshot.editorData, 'math')).toBe(false);+ expect(hasNodeType(snapshot.editorData, 'mathBlock')).toBe(true);+ });+it('should safely serialize concurrent headless document lifecycles', async () => {const sources = await Promise.all(Array.from({ length: 6 }, (_, index) =>diff --git a/apps/server/src/services/agentDocuments/headlessEditor.ts b/apps/server/src/services/agentDocuments/headlessEditor.tsindex b0bc1109e99..05a125d9195 100644--- a/apps/server/src/services/agentDocuments/headlessEditor.ts+++ b/apps/server/src/services/agentDocuments/headlessEditor.ts@@ -6,8 +6,8 @@ import {planLiteXMLEditSteps,touchesList,} from '@lobechat/editor-runtime';-import type { HeadlessLiteXMLOperation } from '@lobehub/editor/headless';-import { createHeadlessEditor } from '@lobehub/editor/headless';+import type { HeadlessEditorOptions, HeadlessLiteXMLOperation } from '@lobehub/editor/headless';+import { createHeadlessEditor, DEFAULT_HEADLESS_EDITOR_PLUGINS } from '@lobehub/editor/headless';import type { SerializedEditorState, SerializedLexicalNode } from 'lexical';import { EMPTY_EDITOR_STATE } from '@/libs/editor/constants';@@ -97,6 +97,22 @@ interface LoadEditorStateParams {// hydrating snapshots with stable ids. Concurrent document reads can therefore// corrupt one another (or observe a partially initialized HeadlessEditor). Keep// the complete create/hydrate/export/destroy lifecycle serialized.+// Documents render in PageEditor, which keeps `$...$` as plain text because+// business writing uses dollar amounts far more than inline formulas. Parse+// Markdown the same way here so CLI and agent writes don't mint inline math+// nodes the editor itself would never create. Block `$$` math is unaffected.+type HeadlessEditorPlugin = NonNullable<HeadlessEditorOptions['plugins']>[number];++const DOCUMENT_HEADLESS_PLUGINS = DEFAULT_HEADLESS_EDITOR_PLUGINS.map(+ (plugin): HeadlessEditorPlugin =>+ !Array.isArray(plugin) && plugin.pluginName === 'MathPlugin'+ ? [plugin, { enableInlineMath: false }]+ : plugin,+);++export const createDocumentHeadlessEditor = () =>+ createHeadlessEditor({ plugins: DOCUMENT_HEADLESS_PLUGINS });+let headlessEditorTail: Promise<void> = Promise.resolve();const withHeadlessEditorLock = async <T>(run: () => Promise<T> | T): Promise<T> => {@@ -187,7 +203,7 @@ export const createMarkdownEditorSnapshot = async (content: string,): Promise<AgentDocumentEditorSnapshot> =>withHeadlessEditorLock(() => {- const editor = createHeadlessEditor();+ const editor = createDocumentHeadlessEditor();try {hydrateMarkdownOrEmptyState(editor, content);@@ -228,7 +244,10 @@ export const exportEditorDataSnapshot = async (params: LoadEditorStateParams & { litexml?: boolean },): Promise<AgentDocumentEditorSnapshot> =>withHeadlessEditorLock(() => {- const { editor, recoveredFromMarkdown } = createEditorWithState(createHeadlessEditor, params);+ const { editor, recoveredFromMarkdown } = createEditorWithState(+ createDocumentHeadlessEditor,+ params,+ );try {const snapshot = exportSnapshot(editor, params.litexml);@@ -247,7 +266,10 @@ export const applyLiteXMLOperations = async ({operations: AgentDocumentLiteXMLOperation[];}): Promise<AgentDocumentEditSnapshot> =>withHeadlessEditorLock(async () => {- const { editor } = createEditorWithState(createHeadlessEditor, { editorData, fallbackContent });+ const { editor } = createEditorWithState(createDocumentHeadlessEditor, {+ editorData,+ fallbackContent,+ });try {const beforeSnapshot = exportSnapshot(editor, true);diff --git a/apps/server/src/services/agentDocuments/index.test.ts b/apps/server/src/services/agentDocuments/index.test.tsindex 9a2fbf63d16..15ba663799c 100644--- a/apps/server/src/services/agentDocuments/index.test.ts+++ b/apps/server/src/services/agentDocuments/index.test.ts@@ -65,6 +65,7 @@ vi.mock('../skill/resource', () => ({}));vi.mock('@lobehub/editor/headless', () => ({+ DEFAULT_HEADLESS_EDITOR_PLUGINS: [],createHeadlessEditor: vi.fn(() => {let markdown = '';let litexml = '<p id="node-1">content</p>';diff --git a/apps/server/src/services/toolExecution/serverRuntimes/pageAgent.ts b/apps/server/src/services/toolExecution/serverRuntimes/pageAgent.tsindex e371f5958ac..986a5a970fe 100644--- a/apps/server/src/services/toolExecution/serverRuntimes/pageAgent.ts+++ b/apps/server/src/services/toolExecution/serverRuntimes/pageAgent.ts@@ -5,12 +5,13 @@ import {type PageAgentRuntimeService,} from '@lobechat/builtin-tool-page-agent/executionRuntime';import { EditorRuntime, formatModifyNodesResult } from '@lobechat/editor-runtime';-import { createHeadlessEditor, type HeadlessEditor } from '@lobehub/editor/headless';+import { type HeadlessEditor } from '@lobehub/editor/headless';import type { SerializedEditorState, SerializedLexicalNode } from 'lexical';import { DocumentModel } from '@/database/models/document';import { type LobeChatDatabase } from '@/database/type';import { isValidEditorData } from '@/libs/editor/isValidEditorData';+import { createDocumentHeadlessEditor } from '@/server/services/agentDocuments/headlessEditor';import { DocumentService } from '@/server/services/document';import type { ServerRuntimeRegistration } from './types';@@ -127,7 +128,7 @@ const loadSnapshot = async (};const buildEnv = (snapshot: DocumentSnapshot, documentId: string): InvocationEnv => {- const headless = createHeadlessEditor();+ const headless = createDocumentHeadlessEditor();let title = snapshot.title;if (isValidEditorData(snapshot.editorData)) {diff --git a/src/features/ChatInput/InputEditor/plugins.ts b/src/features/ChatInput/InputEditor/plugins.tsindex c3ce820da04..6f8e5890327 100644--- a/src/features/ChatInput/InputEditor/plugins.ts+++ b/src/features/ChatInput/InputEditor/plugins.ts@@ -18,7 +18,7 @@ type EditorPlugins = NonNullable<Parameters<typeof Editor>[0]['plugins']>;interface CreateChatInputRichPluginsOptions {linkPlugin?: EditorPlugins[number] | false;- mathPlugin?: EditorPlugins[number];+ mathPlugin?: EditorPlugins[number] | false;}export const CHAT_INPUT_EMBED_PLUGINS: EditorPlugins = [@@ -38,6 +38,6 @@ export const createChatInputRichPlugins = ({ReactHRPlugin,...(linkPlugin ? [linkPlugin] : []),ReactVirtualBlockPlugin,- mathPlugin,+ ...(mathPlugin ? [mathPlugin] : []),...CHAT_INPUT_EMBED_PLUGINS,];diff --git a/src/features/EditorCanvas/EditorCanvas.tsx b/src/features/EditorCanvas/EditorCanvas.tsxindex 271b6c18d77..1371f24125f 100644--- a/src/features/EditorCanvas/EditorCanvas.tsx+++ b/src/features/EditorCanvas/EditorCanvas.tsx@@ -36,6 +36,13 @@ interface UnsavedChangesGuardOptions {}export interface EditorCanvasProps {+ /**+ * Allow block plugins to render outside the editor's normal text column.+ * Keep disabled for compact editor surfaces; PageEditor enables it for wide+ * table scroll areas and their resize controls.+ */+ allowContentBleed?: boolean;+/*** Whether to enable auto-save in DocumentStore. Defaults to true.* Only applies when documentId is provided.@@ -88,6 +95,13 @@ export interface EditorCanvasProps {editorData?: unknown;};+ /**+ * Convert `$...$` input and Markdown inline-math tokens into formula nodes.+ * Defaults to true. PageEditor disables this because business documents use+ * dollar signs far more often than inline formulas.+ */+ enableInlineMath?: boolean;+/*** Entity ID (e.g., agentId, groupId) to track which entity is being edited.* When entityId changes, editor content will be reloaded.diff --git a/src/features/EditorCanvas/InternalEditor.readonly.test.tsx b/src/features/EditorCanvas/InternalEditor.readonly.test.tsxindex fc5a5ec3a0a..8d95ace0dd5 100644--- a/src/features/EditorCanvas/InternalEditor.readonly.test.tsx+++ b/src/features/EditorCanvas/InternalEditor.readonly.test.tsx@@ -44,6 +44,7 @@ vi.mock('@lobehub/editor', () => ({ReactImagePlugin: vi.fn(),ReactLinkPlugin: vi.fn(),ReactLiteXmlPlugin: vi.fn(),+ ReactMathPlugin: vi.fn(),ReactMentionPlugin: vi.fn(),ReactTablePlugin: vi.fn(),ReactToolbarPlugin: vi.fn(),diff --git a/src/features/EditorCanvas/InternalEditor.test.tsx b/src/features/EditorCanvas/InternalEditor.test.tsxindex d2ea3df8ff2..ebfc5bd7cf1 100644--- a/src/features/EditorCanvas/InternalEditor.test.tsx+++ b/src/features/EditorCanvas/InternalEditor.test.tsx@@ -113,6 +113,45 @@ describe('InternalEditor', () => {// The style should include paddingBottom: 32 (default) merged with custom stylesexpect(editorContainer).toBeTruthy();});++ it('should allow wide block controls to bleed outside the text column when enabled', async () => {+ const { container, rerender } = render(<MinimalTestWrapper />);++ await act(async () => {+ await moment();+ });++ expect(container.firstElementChild).toHaveStyle({ overflow: 'hidden' });++ rerender(<MinimalTestWrapper allowContentBleed />);++ expect(container.firstElementChild).toHaveStyle({ overflow: 'visible' });+ });++ it('should keep inline LaTeX as plain text when inline math is disabled', async () => {+ let editorInstance: IEditor | undefined;++ render(+ <TestWrapper+ enableInlineMath={false}+ onEditorReady={(editor) => {+ editorInstance = editor;+ }}+ />,+ );++ await waitFor(() => {+ expect(editorInstance).toBeDefined();+ });++ await act(async () => {+ editorInstance!.setDocument('markdown', 'Budget variable: $x$');+ await moment();+ });++ expect(editorInstance!.getDocument('text')).toBe('Budget variable: $x$');+ expect(JSON.stringify(editorInstance!.getDocument('json'))).not.toContain('"type":"math"');+ });});describe('onInit callback', () => {diff --git a/src/features/EditorCanvas/InternalEditor.tsx b/src/features/EditorCanvas/InternalEditor.tsxindex 5f73387c4cb..f4b6da83778 100644--- a/src/features/EditorCanvas/InternalEditor.tsx+++ b/src/features/EditorCanvas/InternalEditor.tsx@@ -6,6 +6,7 @@ import {ReactImagePlugin,ReactLinkPlugin,ReactLiteXmlPlugin,+ ReactMathPlugin,ReactMentionPlugin,ReactTablePlugin,ReactToolbarPlugin,@@ -48,7 +49,7 @@ const fileNodeStyles = createStaticStyles(({ css }) => ({*/const STATIC_PLUGINS = [ReactLiteXmlPlugin,- ...createChatInputRichPlugins({ linkPlugin: ReactLinkPlugin }),+ ...createChatInputRichPlugins({ linkPlugin: ReactLinkPlugin, mathPlugin: false }),// The kernel reads a plugin's config once at init, and `mentionOption` can// arrive later (workspace pages resolve their member source asynchronously),// so pin the member chip's markdown form here rather than relying on@@ -108,6 +109,7 @@ export interface InternalEditorProps extends EditorCanvasProps {*/const InternalEditor = memo<InternalEditorProps>(({+ allowContentBleed,blockImageCaretGuard = false,className,contentChangeLockRef,@@ -115,6 +117,7 @@ const InternalEditor = memo<InternalEditorProps>(disabled,editable = true,editor,+ enableInlineMath = true,extraPlugins,floatingToolbar = true,getPopupContainer,@@ -153,11 +156,11 @@ const InternalEditor = memo<InternalEditorProps>(maxWidth: '100%',minWidth: 0,opacity: disabled ? 0.65 : undefined,- overflow: 'hidden',+ overflow: allowContentBleed ? 'visible' : 'hidden',pointerEvents: disabled ? 'none' : undefined,width: '100%',}),- [disabled],+ [allowContentBleed, disabled],);// Build plugins array@@ -179,10 +182,12 @@ const InternalEditor = memo<InternalEditorProps>(theme: { file: fileNodeStyles.fileWrapper as unknown as string },});+ const mathPlugin = Editor.withProps(ReactMathPlugin, { enableInlineMath });+// Build base plugins with optional extra plugins prependedconst basePlugins = extraPlugins- ? [...extraPlugins, ...STATIC_PLUGINS, imagePlugin, filePlugin]- : [...STATIC_PLUGINS, imagePlugin, filePlugin];+ ? [...extraPlugins, ...STATIC_PLUGINS, mathPlugin, imagePlugin, filePlugin]+ : [...STATIC_PLUGINS, mathPlugin, imagePlugin, filePlugin];if (!floatingToolbar || disabled) return basePlugins;@@ -232,6 +237,7 @@ const InternalEditor = memo<InternalEditorProps>(editable,editor,editorState,+ enableInlineMath,extraPlugins,floatingToolbar,handleFileUpload,diff --git a/src/features/PageEditor/EditorCanvas/index.tsx b/src/features/PageEditor/EditorCanvas/index.tsxindex 61f1379280c..d01746c7b29 100644--- a/src/features/PageEditor/EditorCanvas/index.tsx+++ b/src/features/PageEditor/EditorCanvas/index.tsx@@ -46,10 +46,12 @@ const EditorCanvas = memo<EditorCanvasProps>(({ askCopilotTarget, placeholder, sreturn (<SharedEditorCanvas+ allowContentBleedclassName={mentionPlainClassName}documentId={documentId}editable={editable}editor={editor}+ enableInlineMath={false}extraPlugins={extraPlugins}mentionOption={mentionOption}placeholder={placeholder || t('pageEditor.editorPlaceholder')}