Functional Transformations
Describe the bug
In the slateToCiceroMarkDom I’m running into this error where node.children is read only and errors because it cannot be reassigned.
The error is
Uncaught TypeError: Cannot assign to read only property 'children' of object '#<Object>' which occurs at that line I linked above.
To Reproduce Steps to reproduce the behavior:
- Link
slate-0.50.xbranch in this editor tocicero-uislate57branch. - Highlight an entire clause template in the demo
- Copy
- See error
Expected behavior
Currently this works: JSON.parse(JSON.stringify(Node.fragment(editor, editor.selection));, but I expect this to not be required.
Screenshots
Additional context
const onCopy = (event) => {
const slateTransformer = new SlateTransformer();
const htmlTransformer = new HtmlTransformer();
const ciceroMarkTransformer = new CiceroMarkTransformer();
const SLATE_CHILDREN = JSON.parse(JSON.stringify(Node.fragment(editor, editor.selection)));
console.log('SLATE_CHILDREN ', SLATE_CHILDREN);
const SLATE_DOM = {
object: 'value',
document: {
object: 'document',
data: {},
children: SLATE_CHILDREN
}
};
console.log('SLATE_DOM ', SLATE_DOM);
const CICERO_MARK_DOM = slateTransformer.toCiceroMark(SLATE_DOM);
console.log('CICERO_MARK_DOM ', CICERO_MARK_DOM);
const HTML_DOM = htmlTransformer.toHtml(CICERO_MARK_DOM);
console.log('HTML_DOM ', HTML_DOM);
const MARKDOWN_TEXT = ciceroMarkTransformer.toMarkdown(CICERO_MARK_DOM);
console.log('MARKDOWN_TEXT ', MARKDOWN_TEXT);
event.preventDefault();
event.clipboardData.setData('text/html', HTML_DOM);
event.clipboardData.setData('text/plain', MARKDOWN_TEXT);
};
The markdown transform expects a plain JSON object. Can you try with that? I'm suspecting that what you are passing isn't proper JSON.
(Note: I believe that's why it's working with JSON.parse(JSON.stringify(...)))
Tracking in https://github.com/ianstormtaylor/slate/issues/3577
Changing title. We need to migrate to a functional approach to transformations and avoid mutations.