mirror of
https://github.com/facebook/lexical.git
synced 2025-05-17 06:59:17 +08:00
This commit is contained in:
@ -980,75 +980,7 @@ test.describe('CodeBlock', () => {
|
||||
</span>
|
||||
</code>
|
||||
`;
|
||||
const EXPECTED_HTML_GOOGLE_SPREADSHEET = html`
|
||||
<table class="PlaygroundEditorTheme__table">
|
||||
<tr style="height: 21px">
|
||||
<td class="PlaygroundEditorTheme__tableCell">
|
||||
<p
|
||||
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
|
||||
dir="ltr">
|
||||
<strong
|
||||
class="PlaygroundEditorTheme__textBold"
|
||||
data-lexical-text="true">
|
||||
Surface
|
||||
</strong>
|
||||
</p>
|
||||
</td>
|
||||
<td class="PlaygroundEditorTheme__tableCell">
|
||||
<p
|
||||
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
|
||||
dir="ltr">
|
||||
<em
|
||||
class="PlaygroundEditorTheme__textItalic"
|
||||
data-lexical-text="true">
|
||||
MWP_WORK_LS_COMPOSER
|
||||
</em>
|
||||
</p>
|
||||
</td>
|
||||
<td class="PlaygroundEditorTheme__tableCell">
|
||||
<p class="PlaygroundEditorTheme__paragraph" style="text-align: right">
|
||||
<span
|
||||
class="PlaygroundEditorTheme__textUnderline"
|
||||
data-lexical-text="true">
|
||||
77349
|
||||
</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr style="height: 21px">
|
||||
<td class="PlaygroundEditorTheme__tableCell">
|
||||
<p
|
||||
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
|
||||
dir="ltr">
|
||||
<span data-lexical-text="true">Lexical</span>
|
||||
</p>
|
||||
</td>
|
||||
<td class="PlaygroundEditorTheme__tableCell">
|
||||
<p
|
||||
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
|
||||
dir="ltr">
|
||||
<span
|
||||
class="PlaygroundEditorTheme__textStrikethrough"
|
||||
data-lexical-text="true">
|
||||
XDS_RICH_TEXT_AREA
|
||||
</span>
|
||||
</p>
|
||||
</td>
|
||||
<td class="PlaygroundEditorTheme__tableCell">
|
||||
<p
|
||||
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
|
||||
dir="ltr">
|
||||
<span data-lexical-text="true">sdvd</span>
|
||||
<strong
|
||||
class="PlaygroundEditorTheme__textBold"
|
||||
data-lexical-text="true">
|
||||
sdfvsfs
|
||||
</strong>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
`;
|
||||
|
||||
const CODE_PASTING_TESTS = [
|
||||
{
|
||||
expectedHTML: EXPECTED_HTML,
|
||||
@ -1121,11 +1053,6 @@ test.describe('CodeBlock', () => {
|
||||
// semantically it should be wrapped in a pre
|
||||
pastedHTML: `<meta charset='utf-8'><code>1<br>2</code>`,
|
||||
},
|
||||
{
|
||||
expectedHTML: EXPECTED_HTML_GOOGLE_SPREADSHEET,
|
||||
name: 'Google Spreadsheet',
|
||||
pastedHTML: `<google-sheets-html-origin><style type="text/css"><!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}--></style><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none" data-sheets-root="1"><colgroup><col width="100"/><col width="189"/><col width="171"/></colgroup><tbody><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-weight:bold;" data-sheets-value="{"1":2,"2":"Surface"}">Surface</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-style:italic;" data-sheets-value="{"1":2,"2":"MWP_WORK_LS_COMPOSER"}">MWP_WORK_LS_COMPOSER</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-decoration:underline;text-align:right;" data-sheets-value="{"1":3,"3":77349}">77349</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;" data-sheets-value="{"1":2,"2":"Lexical"}">Lexical</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-decoration:line-through;" data-sheets-value="{"1":2,"2":"XDS_RICH_TEXT_AREA"}">XDS_RICH_TEXT_AREA</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;" data-sheets-value="{"1":2,"2":"sdvd sdfvsfs"}" data-sheets-textstyleruns="{"1":0}{"1":5,"2":{"5":1}}"><span style="font-size:10pt;font-family:Arial;font-style:normal;">sdvd </span><span style="font-size:10pt;font-family:Arial;font-weight:bold;font-style:normal;">sdfvsfs</span></td></tr></tbody></table>`,
|
||||
},
|
||||
];
|
||||
|
||||
CODE_PASTING_TESTS.forEach((testCase, i) => {
|
||||
|
@ -82,5 +82,23 @@ describe('LexicalTableNode tests', () => {
|
||||
`<table><tr><td><p dir="ltr"><span data-lexical-text="true">Hello there</span></p></td><td><p dir="ltr"><span data-lexical-text="true">General Kenobi!</span></p></td></tr><tr><td><p dir="ltr"><span data-lexical-text="true">Lexical is nice</span></p></td>${emptyCell}</tr></table>`,
|
||||
);
|
||||
});
|
||||
|
||||
test('Copy table from an external source like gdoc with formatting', async () => {
|
||||
const {editor} = testEnv;
|
||||
|
||||
const dataTransfer = new DataTransferMock();
|
||||
dataTransfer.setData(
|
||||
'text/html',
|
||||
'<google-sheets-html-origin><style type="text/css"><!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}--></style><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none" data-sheets-root="1"><colgroup><col width="100"/><col width="189"/><col width="171"/></colgroup><tbody><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-weight:bold;" data-sheets-value="{"1":2,"2":"Surface"}">Surface</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-style:italic;" data-sheets-value="{"1":2,"2":"MWP_WORK_LS_COMPOSER"}">MWP_WORK_LS_COMPOSER</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-decoration:underline;text-align:right;" data-sheets-value="{"1":3,"3":77349}">77349</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;" data-sheets-value="{"1":2,"2":"Lexical"}">Lexical</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-decoration:line-through;" data-sheets-value="{"1":2,"2":"XDS_RICH_TEXT_AREA"}">XDS_RICH_TEXT_AREA</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;" data-sheets-value="{"1":2,"2":"sdvd sdfvsfs"}" data-sheets-textstyleruns="{"1":0}{"1":5,"2":{"5":1}}"><span style="font-size:10pt;font-family:Arial;font-style:normal;">sdvd </span><span style="font-size:10pt;font-family:Arial;font-weight:bold;font-style:normal;">sdfvsfs</span></td></tr></tbody></table>',
|
||||
);
|
||||
await editor.update(() => {
|
||||
const selection = $getSelection();
|
||||
invariant($isRangeSelection(selection), 'isRangeSelection(selection)');
|
||||
$insertDataTransferForRichText(dataTransfer, selection, editor);
|
||||
});
|
||||
expect(testEnv.innerHTML).toBe(
|
||||
`<table><tr style="height: 21px;"><td><p dir="ltr"><strong data-lexical-text="true">Surface</strong></p></td><td><p dir="ltr"><em data-lexical-text="true">MWP_WORK_LS_COMPOSER</em></p></td><td><p style="text-align: right;"><span data-lexical-text="true">77349</span></p></td></tr><tr style="height: 21px;"><td><p dir="ltr"><span data-lexical-text="true">Lexical</span></p></td><td><p dir="ltr"><span data-lexical-text="true">XDS_RICH_TEXT_AREA</span></p></td><td><p dir="ltr"><span data-lexical-text="true">sdvd </span><strong data-lexical-text="true">sdfvsfs</strong></p></td></tr></table>`,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user