|
|
@ -608,20 +608,18 @@ class AiFormat extends Plugin {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 智能识别发送消息
|
|
|
|
// 智能识别发送消息
|
|
|
|
function sendRecMsg(type) {
|
|
|
|
function sendRecMsg(type, editor) {
|
|
|
|
const selection = window.getSelection();
|
|
|
|
//const selection = window.getSelection();
|
|
|
|
|
|
|
|
// const editor = this.editor;
|
|
|
|
|
|
|
|
const model = editor.model;
|
|
|
|
|
|
|
|
const imageUtils=editor.plugins.get( 'ImageUtils' );
|
|
|
|
|
|
|
|
const imageElement = imageUtils.getClosestSelectedImageElement( model.document.selection );
|
|
|
|
const formData = new FormData();
|
|
|
|
const formData = new FormData();
|
|
|
|
var src = '';
|
|
|
|
var src = '';
|
|
|
|
if (type === 'pic_recognition') {
|
|
|
|
if (type === 'pic_recognition') {
|
|
|
|
const range = selection.getRangeAt(0);
|
|
|
|
if (imageElement) {
|
|
|
|
const imageElements = range.commonAncestorContainer.parentNode.querySelectorAll('img');
|
|
|
|
var imageSrc = imageElement.getAttribute('src');
|
|
|
|
if (imageElements.length > 0) {
|
|
|
|
src = imageSrc.replace(/^data:image\/\w+;base64,/, "");
|
|
|
|
const selectedImage = imageElements[0];
|
|
|
|
|
|
|
|
src = selectedImage.getAttribute('src');
|
|
|
|
|
|
|
|
const prefix = "data:image/png;base64,";
|
|
|
|
|
|
|
|
if (src.startsWith(prefix)) {
|
|
|
|
|
|
|
|
src = src.substring(prefix.length);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (src.trim() === '') return;
|
|
|
|
if (src.trim() === '') return;
|
|
|
|
formData.append('pic', src);
|
|
|
|
formData.append('pic', src);
|
|
|
@ -682,7 +680,7 @@ class PicRecog extends Plugin {
|
|
|
|
|
|
|
|
|
|
|
|
// Execute a callback function when the button is clicked
|
|
|
|
// Execute a callback function when the button is clicked
|
|
|
|
button.on('execute', () => {
|
|
|
|
button.on('execute', () => {
|
|
|
|
sendRecMsg('pic_recognition');
|
|
|
|
sendRecMsg('pic_recognition', this.editor);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return button;
|
|
|
|
return button;
|
|
|
|