我正在尝试使用 quill-better-table 库将表插入到 react-quill 中。我注意到这里有一个相关的普通 js 示例:https ://codepen.io/soccerloway/pen/WWJowj使用函数quill.getModule('better-table')来获取模块,然后插入表格。我尝试使用 react-quill 和 react-quill-with-table 来执行此操作,但未定义该功能。库的反应版本可以与 quill-better-table 一起使用吗?
import ReactQuill, { Quill, Mixin, Toolbar } from 'react-quill-with-table'; // ES6
import QuillBetterTable from "quill-better-table";
export default function MyQuillTextEditor(props) {
const modules = {
toolbar: [
[{ 'header': [1, 2, false] }],
['bold', 'italic', 'underline','strike', 'blockquote'],
[{'list': 'ordered'}, {'list': 'bullet'}, {'indent': '-1'}, {'indent': '+1'}],
['link', 'image'],
['clean']
],
table: false, // disable table module
"better-table": {
operationMenu: {
items: {
unmergeCells: {
text: "Another unmerge cells name"
}
}
}
},
keyboard: {
bindings: QuillBetterTable.keyboardBindings
}
}
const formats = [
'header',
'bold', 'italic', 'underline', 'strike', 'blockquote',
'list', 'bullet', 'indent',
'link', 'image'
]
let editor = null;
const addTable = (e) => {
e.preventDefault();
Quill.getModule("better-table");
}
return (
<div>
<ButtonGroup size="small" aria-label="small button group">
<Button onClick>Add Row</Button>
<Button>Add Column</Button>
<Button>Delete Table</Button>
<Button onClick={(event) =>addTable(event)}>Add Table</Button>
</ButtonGroup>
<ReactQuill theme="snow"
ref={(el) =>{editor = el}}
modules={modules}
formats={formats}
theme="snow"
>
</ReactQuill>
</div>
)
}