-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1903 from epam/fix-pasting-tables-from
[SlateEditor] Fix paste tables from word
- Loading branch information
Showing
16 changed files
with
778 additions
and
113 deletions.
There are no files selected for viewing
404 changes: 404 additions & 0 deletions
404
uui-editor/src/__tests__/__snapshots__/serialization.test.tsx.snap
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { createTempEditor } from '../serialization'; | ||
import { | ||
baseMarksPlugin, | ||
headerPlugin, | ||
colorPlugin, | ||
superscriptPlugin, | ||
listPlugin, | ||
toDoListPlugin, | ||
quotePlugin, | ||
linkPlugin, | ||
notePlugin, | ||
uploadFilePlugin, | ||
attachmentPlugin, | ||
imagePlugin, | ||
videoPlugin, | ||
iframePlugin, | ||
separatorPlugin, | ||
tablePlugin, | ||
codeBlockPlugin, | ||
} from '../plugins'; | ||
import { defaultPlugins } from '../defaultPlugins'; | ||
import { createPlateEditor } from '@udecode/plate-core'; | ||
|
||
export const readTestFile = (filepath: string): string => { | ||
const absoluteFilepath = path.resolve(__dirname, filepath); | ||
return fs.readFileSync(absoluteFilepath, 'utf8'); | ||
}; | ||
|
||
export const createClipboardData = (html: string, rtf?: string): DataTransfer => | ||
({ | ||
getData: (format: string) => (format === 'text/html' ? html : rtf), | ||
} as any); | ||
|
||
const plugins = [ | ||
...defaultPlugins, | ||
baseMarksPlugin(), | ||
headerPlugin(), | ||
colorPlugin(), | ||
superscriptPlugin(), | ||
listPlugin(), | ||
toDoListPlugin(), | ||
quotePlugin(), | ||
linkPlugin(), | ||
notePlugin(), | ||
uploadFilePlugin({}), | ||
attachmentPlugin(), | ||
imagePlugin(), | ||
videoPlugin(), | ||
iframePlugin(), | ||
separatorPlugin(), | ||
tablePlugin(), | ||
codeBlockPlugin(), | ||
// placeholderPlugin(), | ||
]; | ||
|
||
const initEditor = () => { | ||
const editor = createTempEditor(plugins); | ||
editor.children = [ | ||
{ | ||
data: {}, | ||
type: 'paragraph', | ||
children: [ | ||
{ | ||
text: '', | ||
}, | ||
], | ||
}, | ||
]; | ||
return createPlateEditor({ editor, plugins }); | ||
}; | ||
|
||
describe('serialization', () => { | ||
it('should paste data with tables', async () => { | ||
const editor = initEditor(); | ||
|
||
const data = createClipboardData(readTestFile('./tables.html')); | ||
editor.insertData(data); | ||
|
||
expect(editor.children).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
<!DOCTYPE html> | ||
<html lang="en-US"> | ||
|
||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta charset="utf-8" /> | ||
<title> | ||
</title> | ||
<style> | ||
body { | ||
font-family: Calibri; | ||
font-size: 12pt | ||
} | ||
|
||
h1, | ||
p { | ||
margin: 0pt | ||
} | ||
|
||
li, | ||
table { | ||
margin-top: 0pt; | ||
margin-bottom: 0pt | ||
} | ||
|
||
h1 { | ||
margin-top: 12pt; | ||
margin-left: 39.6pt; | ||
margin-bottom: 6pt; | ||
text-indent: -21.6pt; | ||
page-break-inside: auto; | ||
page-break-after: avoid; | ||
widows: 0; | ||
orphans: 0; | ||
font-family: 'Liberation Sans'; | ||
font-size: 18pt; | ||
font-weight: bold; | ||
color: #000000 | ||
} | ||
|
||
.BodyText { | ||
margin-bottom: 7pt; | ||
line-height: 120%; | ||
widows: 0; | ||
orphans: 0; | ||
font-family: 'Liberation Serif'; | ||
font-size: 12pt | ||
} | ||
|
||
.TableContents { | ||
widows: 0; | ||
orphans: 0; | ||
font-family: 'Liberation Serif'; | ||
font-size: 12pt | ||
} | ||
|
||
span.BodyTextChar { | ||
font-family: 'Liberation Serif' | ||
} | ||
|
||
span.Heading1Char { | ||
font-family: 'Liberation Sans'; | ||
font-size: 18pt; | ||
font-weight: bold | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<p> | ||
  | ||
</p> | ||
<p> | ||
  | ||
</p> | ||
<table style="border:0.75pt solid #000000; border-collapse:collapse"> | ||
<tr> | ||
<td | ||
style="width:210.6pt; border-right:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding-right:5.03pt; padding-left:5.03pt; vertical-align:top; background-color:#ffff00"> | ||
<p> | ||
Sinple | ||
</p> | ||
</td> | ||
<td | ||
style="width:210.6pt; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #4472c4; padding-right:5.03pt; padding-left:5.03pt; vertical-align:top; background-color:#ffff00"> | ||
<p> | ||
Table | ||
</p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td | ||
style="width:210.6pt; border-top:0.75pt solid #000000; border-right:0.75pt solid #000000; padding-right:5.03pt; padding-left:5.03pt; vertical-align:top"> | ||
<p> | ||
With yellow | ||
</p> | ||
</td> | ||
<td | ||
style="width:210.6pt; border-top:0.75pt solid #4472c4; border-left:0.75pt solid #000000; padding-right:5.03pt; padding-left:5.03pt; vertical-align:top"> | ||
<p> | ||
back | ||
</p> | ||
</td> | ||
</tr> | ||
</table> | ||
<p class="BodyText" | ||
style="margin-bottom:11.25pt; text-align:justify; line-height:120%; widows:2; orphans:2; font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'"> </span> | ||
</p> | ||
<table style="margin-left:2.75pt; border:0.75pt solid #000000; border-collapse:collapse"> | ||
<tr style="height:22.5pt"> | ||
<td | ||
style="width:30.5pt; border-right:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="BodyText" | ||
style="margin-bottom:11.25pt; line-height:120%; widows:2; orphans:2; font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'"> </span> | ||
</p> | ||
</td> | ||
<td | ||
style="width:278pt; border-right:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="BodyText" | ||
style="margin-bottom:11.25pt; line-height:120%; widows:2; orphans:2; font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">Lorem ipsum</span> | ||
</p> | ||
</td> | ||
<td | ||
style="width:72.5pt; border-right:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">Lorem ipsum</span> | ||
</p> | ||
</td> | ||
<td | ||
style="width:79.25pt; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">Lorem ipsum</span> | ||
</p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td | ||
style="width:30.5pt; border-top:0.75pt solid #000000; border-right:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">1</span> | ||
</p> | ||
</td> | ||
<td style="width:278pt; border:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="BodyText" | ||
style="margin-bottom:11.25pt; line-height:120%; widows:2; orphans:2; font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">In eleifend velit vitae libero sollicitudin euismod.</span> | ||
</p> | ||
</td> | ||
<td style="width:72.5pt; border:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">Lorem</span> | ||
</p> | ||
</td> | ||
<td | ||
style="width:79.25pt; border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'"> </span> | ||
</p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td colspan="4" | ||
style="width:476.75pt; border-top:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">2</span> | ||
</p> | ||
<p class="BodyText" | ||
style="margin-bottom:11.25pt; line-height:120%; widows:2; orphans:2; font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">Cras fringilla ipsum magna, in fringilla dui commodo | ||
a.</span> | ||
</p> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">Ipsum</span> | ||
</p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td | ||
style="width:30.5pt; border-top:0.75pt solid #000000; border-right:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">3</span> | ||
</p> | ||
</td> | ||
<td colspan="2" style="width:356pt; border:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="BodyText" | ||
style="margin-bottom:11.25pt; line-height:120%; widows:2; orphans:2; font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">Aliquam erat volutpat. </span> | ||
</p> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">Lorem</span> | ||
</p> | ||
</td> | ||
<td | ||
style="width:79.25pt; border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'"> </span> | ||
</p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td colspan="4" | ||
style="width:476.75pt; border-top:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">4</span> | ||
</p> | ||
<p class="BodyText" | ||
style="margin-bottom:11.25pt; line-height:120%; widows:2; orphans:2; font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">Fusce vitae vestibulum velit. </span> | ||
</p> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">Lorem</span> | ||
</p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td | ||
style="width:30.5pt; border-top:0.75pt solid #000000; border-right:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">5</span> | ||
</p> | ||
</td> | ||
<td | ||
style="width:278pt; border-top:0.75pt solid #000000; border-right:0.75pt solid #000000; border-left:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="BodyText" | ||
style="margin-bottom:11.25pt; line-height:120%; widows:2; orphans:2; font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">Etiam vehicula luctus fermentum.</span> | ||
</p> | ||
</td> | ||
<td | ||
style="width:72.5pt; border-top:0.75pt solid #000000; border-right:0.75pt solid #000000; border-left:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'">Ipsum</span> | ||
</p> | ||
</td> | ||
<td | ||
style="width:79.25pt; border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; padding:2.75pt 2.38pt; vertical-align:top"> | ||
<p class="TableContents" style="font-size:10.5pt"> | ||
<span style="font-family:'DejaVu Sans'"> </span> | ||
</p> | ||
</td> | ||
</tr> | ||
</table> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.