codex-team / codex-team/editor.js
HTML in new component not getting accepted on save
- Dominant language
- TypeScript
- Stars
- 31.9k
- Forks
- 2.2k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 1
Description
Well, i created a new tool for editorjs that is a Collapse
But on description of collapse initially HTML React Quill is accepted, but on save editor js atuomatically clears up the HTML and only saves the text that is inside HTML tags.
Can someone help me?
-------------------
EditorCollapseTool.js
```
import { useState } from 'react';
import { Button, Collapse, Typography } from 'antd'
import { PlusCircleOutlined } from '@ant-design/icons';
import TextArea from 'antd/es/input/TextArea';
import ReactQuill from 'react-quill';
import 'react-quill/dist/quill.snow.css';
const DEFAULT_INITIAL_DATA = () => {
return {
items: [
{
"title": "Title",
"description":
Description
}
],
}
}
const useStyles = {
addButtonText: {
color: '#061848',
fontSize: '16px',
height: 'auto !important',
marginTop: '20px'
}
};
const CollapseTool = (props) => {
const [collapseData, setCollapseData] = useState(props.data.items.length > 0 ? props.data : DEFAULT_INITIAL_DATA);
const updateCollapseData = (newData) => {
setCollapseData(newData);
if (props.onDataChange) {
// Inform editorjs about data change
props.onDataChange(newData);
}
}
const onAddPanel = (e) => {
const newData = {
...collapseData
}
newData.items.push({
"title": "Title",
"description": "Description"
})
updateCollapseData(newData);
}
const onContentChange = (index, fieldName, value) => {
const newData = {
...collapseData
}
console.log(value);
if (fieldName === "description") {
newData.items[index][fieldName] = value;
} else {
newData.items[index][fieldName] = value.target.textContent;
}
updateCollapseData(newData);
}
return (
{collapseData.items.map((event, index) => (
onContentChange(index, 'title', e)}
suppressContentEditableWarning={!props.readOnly}
contentEditable={!props.readOnly}
>
{event.title}
}
>
onContentChange(index, 'description', e)} suppressContentEditableWarning={!props.readOnly} contentEditable={!props.readOnly}>
))}
{
!props.readOnly &&
Adicionar
}
);
}
export default CollapseTool;
```
-------------------
EditorCollpase.js
```
import { default as React } from 'react';
import ReactDOM from 'react-dom';
import CollapseTool from './EditorCollapseTool';
export default class Collapse {
static get toolbox() {
return {
icon: ``,
title: 'Collapse',
};
}
static get isReadOnlySupported() {
return true;
}
constructor({ data, config, api, readOnly }) {
this.api = api;
this.readOnly = readOnly;
this.data = {
items: data.items || [],
};
this.CSS = {
wrapper: 'collapse_item_editor',
};
this.nodes = {
holder: null,
};
}
render() {
const rootNode = document.createElement('div');
rootNode.setAttribute('class', this.CSS.wrapper);
this.nodes.holder = rootNode;
const onDataChange = (newData) => {
console.log(newData);
this.data = {
...newData
};
}
ReactDOM.render(
(
),
rootNode);
return this.nodes.holder;
}
save(blockContent) {
const sanitizerConfig = {
b: true,
a: {
href: true
},
i: true,
p: true,
};
const descriptions = blockContent.querySelectorAll('.ql-editor');
let aux = Object.assign(this.data, {});
for (let i = 0; i < descriptions.length; i++) {
if (descriptions[i].innerHTML) {
aux.items[i].description = this.api.sanitizer.clean(descriptions[i].innerHTML, sanitizerConfig);
}
}
return aux;
}
}
```
-------------------
And here ares some prints of frontend and console logs


Thanks!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.