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.

chore: allow videos inside table cells (#5951)

Wolf Mermelstein85d02156103a
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 6310c632f6..1b245f10bd 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
@@ -7,6 +7,10 @@ import {
$createImageNode,
$isImageNode,
} from '@macro-inc/lexical-core/nodes/ImageNode';
+import {
+ $createVideoNode,
+ $isVideoNode,
+} from '@macro-inc/lexical-core/nodes/VideoNode';
import type { LexicalEditor } from 'lexical';
import { describe, expect, it } from 'vitest';
import {
@@ -49,6 +53,31 @@ describe('table cell allowed content', () => {
});
});
+ it('keeps a video appended to a table cell', async () => {
+ const editor = createTableEditor();
+ await buildTable(editor, textGrid([['hello']]));
+
+ await new Promise<void>((resolve) => {
+ editor.update(
+ () => {
+ $getCell(0, 0).append(
+ $createVideoNode({
+ srcType: 'url',
+ url: 'https://example.com/clip.mp4',
+ })
+ );
+ },
+ { onUpdate: () => resolve() }
+ );
+ });
+
+ editor.read(() => {
+ const video = $getCell(0, 0).getChildren().find($isVideoNode);
+ expect(video).toBeDefined();
+ expect(video?.getUrl()).toBe('https://example.com/clip.mp4');
+ });
+ });
+
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 966835e601..28c36c96fd 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
@@ -73,6 +73,7 @@ function _registerTablePlugin(editor: LexicalEditor, props: TablePluginProps) {
'code',
'custom-code',
'image',
+ 'video',
];
return editor.registerNodeTransform(TableCellNode, (node) => {
const children = node.getChildren();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/styles.css b/apps/web/src/lib/core/component/LexicalMarkdown/styles.css
index 0829077e01..29ef3ba4c1 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/styles.css
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/styles.css
@@ -386,8 +386,9 @@ in a cell — move the indent inside the box so markers stay visible.
padding-left: 1.5em;
}
-/* Keep images from stretching the cell wider than the column. */
-.md-table-cell img {
+/* Keep images and videos from stretching the cell wider than the column. */
+.md-table-cell img,
+.md-table-cell video {
max-width: 100%;
}
diff --git a/packages/lexical-core/tests/tables.test.ts b/packages/lexical-core/tests/tables.test.ts
index c52ba29622..a68204239a 100644
--- a/packages/lexical-core/tests/tables.test.ts
+++ b/packages/lexical-core/tests/tables.test.ts
@@ -25,6 +25,7 @@ import {
import { describe, expect, it } from 'vitest';
import { SupportedNodeTypes } from '../node-list';
import { $createImageNode, $isImageNode } from '../nodes/ImageNode';
+import { $createVideoNode, $isVideoNode } from '../nodes/VideoNode';
import { EXTERNAL_TRANSFORMERS, INTERNAL_TRANSFORMERS } from '../transformers';
function createTestEditor() {
@@ -419,6 +420,94 @@ describe('images inside table cells', () => {
});
});
+describe('videos inside table cells', () => {
+ function $getFirstCellVideo() {
+ const table = $getFirstTable();
+ const [row] = table.getChildren().filter($isTableRowNode);
+ const [cell] = (row as TableRowNode).getChildren().filter($isTableCellNode);
+ const video = cell
+ .getChildren()
+ .flatMap((child) =>
+ $isVideoNode(child)
+ ? [child]
+ : $isElementNode(child)
+ ? child.getChildren().filter($isVideoNode)
+ : []
+ )[0];
+ expect(video).toBeDefined();
+ return video!;
+ }
+
+ it('round-trips a video in a cell through internal markdown', async () => {
+ const editor = createTestEditor();
+
+ await buildEditorState(editor, () => {
+ const table = $createTableNode();
+ const row = $createTableRowNode();
+ const cell = $createTableCellNode(TableCellHeaderStates.NO_STATUS);
+ cell.append(
+ $createVideoNode({
+ srcType: 'url',
+ url: 'https://example.com/clip.mp4',
+ width: 400,
+ height: 300,
+ constrainedWidth: 200,
+ constrainedHeight: 150,
+ })
+ );
+ row.append(cell);
+ table.append(row);
+ $getRoot().append(table);
+ });
+
+ const markdown = exportMarkdown(editor);
+ expect(markdown).toContain('<m-video>');
+ expect(markdown).toContain('https://example.com/clip.mp4');
+ expect(markdown).toContain('"constrainedWidth":200');
+
+ await importMarkdown(editor, markdown);
+ editor.getEditorState().read(() => {
+ const video = $getFirstCellVideo();
+ expect(video.getUrl()).toBe('https://example.com/clip.mp4');
+ expect(video.getConstrainedWidth()).toBe(200);
+ expect(video.getConstrainedHeight()).toBe(150);
+ });
+ });
+
+ it('round-trips a video in a cell through external pipe-table markdown', async () => {
+ const editor = createTestEditor();
+
+ await buildEditorState(editor, () => {
+ const table = $createTableNode();
+ const row = $createTableRowNode();
+ const videoCell = $createTableCellNode(TableCellHeaderStates.NO_STATUS);
+ videoCell.append(
+ $createVideoNode({
+ srcType: 'url',
+ url: 'https://example.com/clip.mp4',
+ })
+ );
+ row.append(videoCell, $createCell('plain'));
+ table.append(row);
+ $getRoot().append(table);
+ });
+
+ const markdown = exportMarkdown(editor, EXTERNAL_TRANSFORMERS);
+ expect(markdown).toContain('<m-video>');
+ expect(markdown).toContain('|');
+ expect(markdown).toContain('plain');
+
+ await buildEditorState(editor, () => {
+ $getRoot().clear();
+ $convertFromMarkdownString(markdown, EXTERNAL_TRANSFORMERS);
+ });
+ editor.getEditorState().read(() => {
+ const video = $getFirstCellVideo();
+ expect(video.getUrl()).toBe('https://example.com/clip.mp4');
+ });
+ });
+});
+
describe('pipe table external transformer', () => {
it('pads merged cells so exported rows stay rectangular', async () => {
const editor = createTestEditor();
diff --git a/packages/lexical-core/transformers/tables.ts b/packages/lexical-core/transformers/tables.ts
index 43787c854e..41e7c5114e 100644
--- a/packages/lexical-core/transformers/tables.ts
+++ b/packages/lexical-core/transformers/tables.ts
@@ -32,6 +32,7 @@ import {
I_USER_MENTION,
} from "./mentions";
import { BR_TAG_TO_LINE_BREAK, HTML_ENTITY_TRANSFORMERS } from "./transformers";
+import { I_VIDEO } from "./video";
// Internal Table Node
@@ -100,6 +101,7 @@ const internalTransformersWithinTables: Transformer[] = [
I_EQUATION_NODE,
I_IMAGE_CONSTRAINED,
IMAGE,
+ I_VIDEO,
...TRANSFORMERS,
];
@@ -247,6 +249,7 @@ const externalTransformersWithinTables: Transformer[] = [
E_CONTACT_MENTION,
E_BLOCK_EQUATION_NODE,
IMAGE,
+ I_VIDEO,
...HTML_ENTITY_TRANSFORMERS,
...TRANSFORMERS,
];
diff --git a/packages/lexical-core/transformers/video.ts b/packages/lexical-core/transformers/video.ts
index fef81cc509..78b79fb767 100644
--- a/packages/lexical-core/transformers/video.ts
+++ b/packages/lexical-core/transformers/video.ts
@@ -10,7 +10,7 @@ import {
export const I_VIDEO: ElementTransformer = {
dependencies: [VideoNode, UnknownMentionNode],
type: 'element',
- regExp: /<m-video>(.*?)<\/m-video>/,
+ regExp: /^<m-video>(.*?)<\/m-video>\s*$/,
export: (node: LexicalNode) => {
if (!$isVideoNode(node)) return null;
if (node.getSrcType() === 'local') return null;