-
-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac88ec4
commit 817234e
Showing
9 changed files
with
271 additions
and
58 deletions.
There are no files selected for viewing
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
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,184 @@ | ||
import { serializePlateStatic } from '../serializedHtml'; | ||
import { createStaticEditor, staticComponents } from './create-static-editor'; | ||
|
||
describe('serializePlateStatic nodes', () => { | ||
// it('should serialize complex example list with paragraphs to html', async () => { | ||
// const editor = createStaticEditor([ | ||
// { | ||
// children: [ | ||
// { | ||
// text: 'Some paragraph that contains, ', | ||
// }, | ||
// { | ||
// italic: true, | ||
// text: 'italicized text', | ||
// }, | ||
// { | ||
// text: ' and ', | ||
// }, | ||
// { | ||
// bold: true, | ||
// text: 'bolded text', | ||
// }, | ||
// { | ||
// text: ' is first.', | ||
// }, | ||
// ], | ||
// type: 'p', | ||
// }, | ||
// { | ||
// children: [ | ||
// { | ||
// children: [ | ||
// { | ||
// children: [ | ||
// { | ||
// text: 'Item one in list', | ||
// }, | ||
// ], | ||
// type: 'p', | ||
// }, | ||
// ], | ||
// type: 'li', | ||
// }, | ||
// { | ||
// children: [ | ||
// { | ||
// children: [ | ||
// { | ||
// text: 'Item two in list', | ||
// }, | ||
// ], | ||
// type: 'p', | ||
// }, | ||
// ], | ||
// type: 'li', | ||
// }, | ||
// ], | ||
// type: 'ul', | ||
// }, | ||
// ]); | ||
|
||
// const html = await serializePlateStatic(editor, staticComponents, { | ||
// preserveClassNames: [], | ||
// stripClassNames: true, | ||
// stripDataAttributes: true, | ||
// }); | ||
|
||
// expect(html).toContain( | ||
// '<p>Some paragraph that contains, <em><span>italicized text</span></em> and <strong><span>bolded text</span></strong> is first.</p>' | ||
// ); | ||
// expect(html).toContain( | ||
// '<ul><li><p>Item one in list</p></li><li><p>Item two in list</p></li></ul>' | ||
// ); | ||
// }); | ||
|
||
// it('should serialize complex example with no type on top level node to html', async () => { | ||
// const editor = createStaticEditor([ | ||
// { | ||
// children: [ | ||
// { | ||
// text: 'Some paragraph that contains, ', | ||
// }, | ||
// { | ||
// italic: true, | ||
// text: 'italicized text', | ||
// }, | ||
// { | ||
// text: ' and ', | ||
// }, | ||
// { | ||
// bold: true, | ||
// text: 'bolded text', | ||
// }, | ||
// { | ||
// text: ' is first.', | ||
// }, | ||
// ], | ||
// type: 'p', | ||
// }, | ||
// ]); | ||
|
||
// const html = await serializePlateStatic(editor, staticComponents, { | ||
// preserveClassNames: [], | ||
// stripClassNames: true, | ||
// stripDataAttributes: true, | ||
// }); | ||
|
||
// expect(html).toContain( | ||
// '<p>Some paragraph that contains, <em><span>italicized text</span></em> and <strong><span>bolded text</span></strong> is first.</p>' | ||
// ); | ||
// }); | ||
|
||
// it('should serialize complex example with multiple no types on top level node to html', async () => { | ||
// const editor = createStaticEditor([ | ||
// { | ||
// children: [ | ||
// { | ||
// text: 'Some paragraph that contains, ', | ||
// }, | ||
// { | ||
// italic: true, | ||
// text: 'italicized text', | ||
// }, | ||
// { | ||
// text: ' and ', | ||
// }, | ||
// { | ||
// bold: true, | ||
// text: 'bolded text', | ||
// }, | ||
// { | ||
// text: ' is first.', | ||
// }, | ||
// ], | ||
// type: 'p', | ||
// }, | ||
// { | ||
// children: [{ bold: true, text: 'FOO' }], | ||
// type: 'p', | ||
// }, | ||
// ]); | ||
|
||
// const html = await serializePlateStatic(editor, staticComponents, { | ||
// preserveClassNames: [], | ||
// stripClassNames: true, | ||
// stripDataAttributes: true, | ||
// }); | ||
|
||
// expect(html).toContain( | ||
// '<p>Some paragraph that contains, <em><span>italicized text</span></em> and <strong><span>bolded text</span></strong> is first.</p>' | ||
// ); | ||
// expect(html).toContain('<strong><span>FOO</span></strong>'); | ||
// }); | ||
|
||
it('should serialize string with %', async () => { | ||
const editor = createStaticEditor([ | ||
{ | ||
children: [ | ||
{ | ||
text: 'None encoded string 100%', | ||
}, | ||
], | ||
type: 'p', | ||
}, | ||
{ | ||
children: [{ text: 'Encoded string 100%25' }], | ||
type: 'p', | ||
}, | ||
]); | ||
|
||
const html = await serializePlateStatic(editor, staticComponents, { | ||
preserveClassNames: [], | ||
stripClassNames: true, | ||
// stripDataAttributes: true, | ||
}); | ||
|
||
expect(html).toContain( | ||
'<div data-slate-node="element><span data-slate-leaf="true"><span data-slate-string="true">None encoded string 100%</span></span></div>' | ||
); | ||
// expect(html).toContain( | ||
// '<div><span data-slate-leaf="true"><span data-slate-string="true">Encoded string 100%25</span></span></div>' | ||
// ); | ||
}); | ||
}); |
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
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
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
46 changes: 46 additions & 0 deletions
46
packages/core/src/lib/static/utils/getRenderStaticNodeProps.ts
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,46 @@ | ||
import type { AnyObject } from '@udecode/utils'; | ||
import type { Path } from 'slate'; | ||
|
||
import { findNode } from '@udecode/slate'; | ||
import clsx from 'clsx'; | ||
|
||
import type { SlateEditor } from '../../editor'; | ||
import type { StaticElementProps } from '../type'; | ||
|
||
import { type SlatePlugin, getEditorPlugin } from '../../plugin'; | ||
import { getSlateClass, pipeInjectNodeProps } from '../../utils'; | ||
import { getPluginNodeProps } from '../../utils/getPluginNodeProps'; | ||
|
||
export const getRenderStaticNodeProps = ({ | ||
attributes, | ||
editor, | ||
plugin, | ||
props, | ||
}: { | ||
editor: SlateEditor; | ||
props: StaticElementProps; | ||
attributes?: AnyObject; | ||
plugin?: SlatePlugin; | ||
}): StaticElementProps => { | ||
props = getPluginNodeProps(props, plugin, attributes); | ||
|
||
const { className } = props; | ||
|
||
let nodeProps = { | ||
...props, | ||
...(plugin ? getEditorPlugin(editor, plugin) : {}), | ||
className: clsx(getSlateClass(plugin?.node.type), className), | ||
}; | ||
|
||
nodeProps = pipeInjectNodeProps( | ||
editor, | ||
nodeProps, | ||
(node) => findNode(editor, { match: (n) => n === node })?.[1] as Path | ||
); | ||
|
||
if (nodeProps.style && Object.keys(nodeProps.style).length === 0) { | ||
delete nodeProps.style; | ||
} | ||
|
||
return nodeProps; | ||
}; |