|
|
@ -4,7 +4,7 @@
|
|
|
|
* @Github:
|
|
|
|
* @Github:
|
|
|
|
* @Date: 2019-12-18 08:49:30
|
|
|
|
* @Date: 2019-12-18 08:49:30
|
|
|
|
* @LastEditors : tangjiang
|
|
|
|
* @LastEditors : tangjiang
|
|
|
|
* @LastEditTime : 2020-01-06 16:45:50
|
|
|
|
* @LastEditTime : 2020-01-09 11:01:51
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
import './index.scss';
|
|
|
|
import './index.scss';
|
|
|
|
import 'quill/dist/quill.core.css'; // 核心样式
|
|
|
|
import 'quill/dist/quill.core.css'; // 核心样式
|
|
|
@ -18,11 +18,12 @@ import deepEqual from './deepEqual.js'
|
|
|
|
import { fetchUploadImage } from '../../services/ojService.js';
|
|
|
|
import { fetchUploadImage } from '../../services/ojService.js';
|
|
|
|
import { getImageUrl } from 'educoder'
|
|
|
|
import { getImageUrl } from 'educoder'
|
|
|
|
import ImageBlot from './ImageBlot';
|
|
|
|
import ImageBlot from './ImageBlot';
|
|
|
|
|
|
|
|
import { Modal } from 'antd';
|
|
|
|
// import Toolbar from 'quill/modules/toolbar';
|
|
|
|
// import Toolbar from 'quill/modules/toolbar';
|
|
|
|
import FillBlot from './FillBlot';
|
|
|
|
import FillBlot from './FillBlot';
|
|
|
|
const Size = Quill.import('attributors/style/size');
|
|
|
|
const Size = Quill.import('attributors/style/size');
|
|
|
|
const Font = Quill.import('formats/font');
|
|
|
|
const Font = Quill.import('formats/font');
|
|
|
|
|
|
|
|
const { confirm } = Modal;
|
|
|
|
// const Color = Quill.import('attributes/style/color');
|
|
|
|
// const Color = Quill.import('attributes/style/color');
|
|
|
|
Size.whitelist = ['12px', '14px', '16px', '18px', '20px', false];
|
|
|
|
Size.whitelist = ['12px', '14px', '16px', '18px', '20px', false];
|
|
|
|
Font.whitelist = ['SimSun', 'SimHei','Microsoft-YaHei','KaiTi','FangSong','Arial','Times-New-Roman','sans-serif'];
|
|
|
|
Font.whitelist = ['SimSun', 'SimHei','Microsoft-YaHei','KaiTi','FangSong','Arial','Times-New-Roman','sans-serif'];
|
|
|
@ -36,6 +37,7 @@ Quill.register(Font, true);
|
|
|
|
Quill.register(FillBlot);
|
|
|
|
Quill.register(FillBlot);
|
|
|
|
// Quill.register(Color);
|
|
|
|
// Quill.register(Color);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function QuillForEditor ({
|
|
|
|
function QuillForEditor ({
|
|
|
|
placeholder,
|
|
|
|
placeholder,
|
|
|
|
readOnly,
|
|
|
|
readOnly,
|
|
|
@ -79,10 +81,44 @@ function QuillForEditor ({
|
|
|
|
|
|
|
|
|
|
|
|
const renderOptions = options || defaultConfig;
|
|
|
|
const renderOptions = options || defaultConfig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const bindings = {
|
|
|
|
|
|
|
|
tab: {
|
|
|
|
|
|
|
|
key: 9,
|
|
|
|
|
|
|
|
handler: function () {
|
|
|
|
|
|
|
|
console.log('调用了tab=====>>>>');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
enter: {
|
|
|
|
|
|
|
|
key: 'Enter',
|
|
|
|
|
|
|
|
handler: function () {
|
|
|
|
|
|
|
|
console.log('enter====>>>>>>');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
backspace: {
|
|
|
|
|
|
|
|
key: 'Backspace',
|
|
|
|
|
|
|
|
handler: function (range, context) {
|
|
|
|
|
|
|
|
console.log('调用了删除按钮', range, context);
|
|
|
|
|
|
|
|
// 1. 获取删除的文件
|
|
|
|
|
|
|
|
// 2. 判断删除的文件中包含空格的个数
|
|
|
|
|
|
|
|
// 3. 循环调用删除方法
|
|
|
|
|
|
|
|
const r = window.confirm('确定要删除吗?')
|
|
|
|
|
|
|
|
console.log('+++++', quill);
|
|
|
|
|
|
|
|
if (r) {
|
|
|
|
|
|
|
|
// 调用传入的删除事件
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
// quill 配置信息
|
|
|
|
// quill 配置信息
|
|
|
|
const quillOption = {
|
|
|
|
const quillOption = {
|
|
|
|
modules: {
|
|
|
|
modules: {
|
|
|
|
toolbar: renderOptions
|
|
|
|
toolbar: renderOptions,
|
|
|
|
|
|
|
|
keyboard: {
|
|
|
|
|
|
|
|
bindings: bindings
|
|
|
|
|
|
|
|
}
|
|
|
|
// toolbar: {
|
|
|
|
// toolbar: {
|
|
|
|
// container: renderOptions
|
|
|
|
// container: renderOptions
|
|
|
|
// }
|
|
|
|
// }
|
|
|
@ -98,8 +134,14 @@ function QuillForEditor ({
|
|
|
|
const quillNode = document.createElement('div');
|
|
|
|
const quillNode = document.createElement('div');
|
|
|
|
editorRef.current.appendChild(quillNode);
|
|
|
|
editorRef.current.appendChild(quillNode);
|
|
|
|
const _quill = new Quill(editorRef.current, quillOption);
|
|
|
|
const _quill = new Quill(editorRef.current, quillOption);
|
|
|
|
setQuill(_quill);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// _quill.keyboard.addBinding({
|
|
|
|
|
|
|
|
// key: 'tab'
|
|
|
|
|
|
|
|
// }, function (range, context) {
|
|
|
|
|
|
|
|
// console.log('点击了键盘的删除按钮: ', range, context);
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setQuill(_quill);
|
|
|
|
// 处理图片上传功能
|
|
|
|
// 处理图片上传功能
|
|
|
|
_quill.getModule('toolbar').addHandler('image', (e) => {
|
|
|
|
_quill.getModule('toolbar').addHandler('image', (e) => {
|
|
|
|
const input = document.createElement('input');
|
|
|
|
const input = document.createElement('input');
|
|
|
@ -142,6 +184,12 @@ function QuillForEditor ({
|
|
|
|
// 点击填空图标时,插入一个下划线
|
|
|
|
// 点击填空图标时,插入一个下划线
|
|
|
|
// 1. 获取编辑器内容
|
|
|
|
// 1. 获取编辑器内容
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 1.获取键盘删除事件
|
|
|
|
|
|
|
|
* 2.点击时获取删除的叶子节点 getLeaf(range.index)
|
|
|
|
|
|
|
|
*/
|
|
|
|
}, []);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
// 设置值
|
|
|
|
// 设置值
|
|
|
@ -232,6 +280,7 @@ function QuillForEditor ({
|
|
|
|
}, [quill, handleOnChange]);
|
|
|
|
}, [quill, handleOnChange]);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
if (!quill) return;
|
|
|
|
if (autoFocus) {
|
|
|
|
if (autoFocus) {
|
|
|
|
quill.focus();
|
|
|
|
quill.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|