Вот как я настраиваю этот экземпляр quill:
Код: Выделить всё
Quill.register('modules/imageDropAndPaste', QuillImageDropAndPaste);
Quill.register('modules/blotFormatter', BlotFormatter);
const custom = ref(['link', 'image', 'video']);
if (props.customToolbar) {
custom.value = ['link', 'video'];
}
const toolbarOptions = [
[{ header: [1, 2, 3, 4, false] }],
[{ size: ['small', false, 'large', 'huge'] }],
['bold', 'underline', 'italic', 'strike'],
[{ align: [] }],
[{ list: 'bullet' }],
[{ list: 'ordered' }],
[{ color: ['#715192', '#52B99E', '#F45E54', '#009BDF', '#FFB81D', '#FE5F8A', '#36558E', '#F4F4F4', '#8D8C8C', '#464646', '#A282C3', '#A3E3D2', '#FFB2AD', '#A3D8E3'] }, { background: ['#715192', '#52B99E', '#F45E54', '#009BDF', '#FFB81D', '#FE5F8A', '#36558E', '#F4F4F4', '#8D8C8C', '#464646', '#A282C3', '#A3E3D2', '#FFB2AD', '#A3D8E3'] }],
['blockquote', 'code-block'],
[{ script: 'sub' }, { script: 'super' }],
custom.value
];
const commentToolbar = [
['bold', 'underline', 'italic'],
[{ list: 'bullet' }],
[{ color: ['#715192', '#52B99E', '#F45E54', '#009BDF', '#FFB81D', '#FE5F8A', '#36558E', '#F4F4F4', '#8D8C8C', '#464646', '#A282C3', '#A3E3D2', '#FFB2AD', '#A3D8E3'] }, { background: ['#715192', '#52B99E', '#F45E54', '#009BDF', '#FFB81D', '#FE5F8A', '#36558E', '#F4F4F4', '#8D8C8C', '#464646', '#A282C3', '#A3E3D2', '#FFB2AD', '#A3D8E3'] }],
['link']
];
const editor = ref(null);
let quill = null;
const setupQuill = () => {
const modules = {
toolbar: { container: props.comment ? commentToolbar : toolbarOptions },
imageDropAndPaste: {}
};
if (!props.readOnly) {
modules.blotFormatter = {};
}
quill = new Quill(editor.value, {
modules,
theme: 'snow',
readOnly: props.readOnly,
placeholder: props.placeholder
});
quill.on('text-change', () => {
emit('update:modelValue', JSON.stringify(quill.getContents()));
});
if (props.twoWayBinding) {
watch(() => props.modelValue, (newVal) => {
if (!quill) return;
const current = JSON.stringify(quill.getContents());
if (newVal && newVal !== current) {
quill.setContents(JSON.parse(newVal));
}
});
}
quill.getModule('toolbar').addHandler('image', () => {
const input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*');
input.click();
input.onchange = async () => {
const file = input.files[0];
if (file) {
const previewUrl = URL.createObjectURL(file);
const range = quill.getSelection();
quill.insertEmbed(range.index, 'image', previewUrl, 'user');
//some more logic here
}
};
});
if (props.modelValue) {
quill.setContents(JSON.parse(props.modelValue));
}
};
onMounted(() => {
const BaseImage = Quill.import('formats/image');
class ImageBlot extends BaseImage {
static sanitize(url) {
if (url.startsWith('blob:')) return url;
return super.sanitize(url);
}
}
Quill.register(ImageBlot, true);
if (editor.value) {
setupQuill();
}
});
Код: Выделить всё
{ insert: {image: "url"} }
{ attributes: { align: "center" }, insert: "\n" }
Код: Выделить всё
[
{
"attributes": {
"height": "375.6024516480523",
"width": "465"
},
"insert": {
"image": "url"
}
},
{
"insert": "\n"
}
]
chatgpt предположил, что проблема может заключаться в том, что модули несовместимы с моей версией quill:
Код: Выделить всё
"quill": "^2.0.2",
"quill-blot-formatter": "^1.0.5",
"quill-image-drop-and-paste": "^1.3.0",
Подробнее здесь: https://stackoverflow.com/questions/798 ... -attribute