Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(md): keep lists inside table cells (#8810)

Wolf Mermelsteinb7dce76c1095
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tableCellContent.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tableCellContent.test.ts
index 164135794f..b7a969c963 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tableCellContent.test.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tableCellContent.test.ts
@@ -1,4 +1,11 @@
import { $createLinkNode } from '@lexical/link';
+import {
+ $createListItemNode,
+ $isListNode,
+ INSERT_ORDERED_LIST_COMMAND,
+ INSERT_UNORDERED_LIST_COMMAND,
+ registerList,
+} from '@lexical/list';
import {
$createTableNode,
$createTableRowNode,
@@ -12,6 +19,10 @@ import {
$createImageNode,
$isImageNode,
} from '@macro-inc/lexical-core/nodes/ImageNode';
+import {
+ $isTaskListNode,
+ TaskListNode,
+} from '@macro-inc/lexical-core/nodes/TaskListNode';
import {
$createVideoNode,
$isVideoNode,
@@ -23,6 +34,7 @@ import {
$getCell,
buildTable,
createTableTestEditor,
+ placeCaret,
textGrid,
} from './tableTestUtils';
@@ -153,6 +165,57 @@ describe('table cell allowed content', () => {
});
});
+ it.each(['bullet', 'number', 'check'] as const)(
+ 'keeps a %s list appended to a table cell',
+ async (listType) => {
+ const editor = createTableEditor();
+ await buildTable(editor, textGrid([['hello']]));
+
+ await new Promise<void>((resolve) => {
+ editor.update(
+ () => {
+ const list = new TaskListNode(listType);
+ const item = $createListItemNode();
+ item.append($createTextNode('item'));
+ list.append(item);
+ $getCell(0, 0).append(list);
+ },
+ { onUpdate: () => resolve() }
+ );
+ });
+
+ editor.read(() => {
+ const list = $getCell(0, 0).getChildren().find($isTaskListNode);
+ expect(list).toBeDefined();
+ expect(list?.getListType()).toBe(listType);
+ expect(list?.getTextContent()).toBe('item');
+ });
+ }
+ );
+
+ it.each([
+ ['bullet', INSERT_UNORDERED_LIST_COMMAND],
+ ['number', INSERT_ORDERED_LIST_COMMAND],
+ ] as const)(
+ 'keeps cell text when converting a paragraph to a %s list',
+ async (listType, command) => {
+ const editor = createTableEditor();
+ registerList(editor);
+ await buildTable(editor, textGrid([['keep me']]));
+ await placeCaret(editor, 'keep me');
+
+ editor.dispatchCommand(command, undefined);
+ await Promise.resolve();
+
+ editor.read(() => {
+ const list = $getCell(0, 0).getChildren().find($isListNode);
+ expect(list).toBeDefined();
+ expect(list?.getListType()).toBe(listType);
+ expect($getCell(0, 0).getTextContent()).toBe('keep me');
+ });
+ }
+ );
+
it('still strips nested tables from cells', async () => {
const editor = createTableEditor();
await buildTable(editor, textGrid([['hello']]));
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tablePlugin.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tablePlugin.ts
index 5da815022a..8bed885639 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tablePlugin.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tablePlugin.ts
@@ -74,6 +74,8 @@ function _registerTablePlugin(editor: LexicalEditor, props: TablePluginProps) {
'paragraph',
'heading',
'list',
+ // ListNode is replaced by TaskListNode at runtime.
+ 'task-list',
'quote',
'code',
'custom-code',
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tableTestUtils.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tableTestUtils.ts
index 83b29410f1..8e0637792a 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tableTestUtils.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tableTestUtils.ts
@@ -11,7 +11,10 @@ import {
type TableCellNode,
type TableNode,
} from '@lexical/table';
-import { SupportedNodeTypes } from '@macro-inc/lexical-core/node-list';
+import {
+ NodeReplacements,
+ SupportedNodeTypes,
+} from '@macro-inc/lexical-core/node-list';
import {
$createParagraphNode,
$createTextNode,
@@ -56,7 +59,7 @@ export function createTableTestEditor(
const editor = createEditor({
namespace: 'table-test',
- nodes: SupportedNodeTypes,
+ nodes: [...SupportedNodeTypes, ...NodeReplacements],
onError: (error) => {
throw error;
},
diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.md
index ae358d18d4..7e49a5be2a 100644
--- a/docs/agent-guide/documents.md
+++ b/docs/agent-guide/documents.md
@@ -2368,6 +2368,8 @@ AI text-writing operations require a paragraph/list-item or text-run ID. A
table, row, cell, or list-container ID is rejected with guidance to choose a
content block or use `setCell`. Existing stray inline content directly inside
table cells is preserved in paragraphs when the editor opens the document.
+Bullet, numbered, and check lists stay in table cells; converting a cell
+paragraph to a list keeps the text.
`@` opens the mention menu wherever the caret starts a word, including directly
in front of existing text — the menu opens empty there instead of searching for