quill-clipboard-plugin
A quill editor module plugin for clipboard pasted files, it can help you filter clipboard file size and mimetypes, and provides a hook to help you substituted error files.
Install
npm install quill-clipboard-plugin -S
yarn add quill-clipboard-plugin -S
Usage
Import
import Quill from 'quill';
import ClipboardPlugin from 'quill-clipboard-plugin';
Quill.register({
'modules/clipboardPlugin': ClipboardPlugin,
});
const quill = new Quill('#your-editor-container', {
modules: {
clipboardPlugin: {},
},
});
Option
const modules = {
clipboardPlugin: {
mimetypes: ['image/png', 'image/jpeg'],
limitSize: [
{
size: 1024 * 1024 * 10,
},
],
errorCallBack: errorCallBack
}
}
function errorCallBack (type): IVDoc {
return {
targetName: 'div';
attr: {
class: 'container'
};
style?: {
height: '100px',
width: '100px !important',
};
children: [
];
text: 'This pic size is more then 10MB';
isStatic: false;
}
}
type IFailType = 'size' | 'type' | 'reg' | 'other';
interface ClipboardPluginOption {
mimetypes: string[];
limitSize: ILimitSizeMap[];
urlReg?: RegExp;
slot?: IVDoc;
errorCallBack(arg: IFailType): IVDoc;
beforePaste(arg: string): string | void;
}
interface ILimitSizeMap {
size: number;
mimetypes?: string[];
}
interface IVDoc {
targetName?: string;
attr?: {
[x in string]: any;
};
style?: string | Record<string, string>[] | Record<string, string>;
children?: IVDoc[];
text?: string | number;
isStatic?: boolean;
}