quill-resize-image
v1.0.12
Published
<p align="center"> <a href="https://www.npmjs.com/package/quill-resize-image" target="_blank" rel="noopener noreferrer"> <img src="https://api.iconify.design/fluent:resize-image-20-filled.svg?color=%23fdb4e2" alt="logo" width='100'/></a> </p>
Maintainers
Readme
Demo
Install
npm i quill-resize-image@latestWith yarn
yarn add quill-resize-imageReactjs
import ReactQuill, { Quill } from 'react-quill';
import QuillResizeImage from 'quill-resize-image';
/**
- add object resize to modules.
**/
// resize: {
// locale: {},
// },
Quill.register("modules/resize", window.QuillResizeImage);
const App = () => {
const Editor = {
modules: {
toolbar: {
container: [
['image'],
],
},
resize: {
locale: {},
},
},
formats: [
'image',
],
};
return <ReactQuill
modules={Editor.modules}
formats={Editor.formats}
theme='snow'
/>
}
Browser
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link
crossorigin="anonymous"
integrity="sha384-7kltdnODhBho8GSWnwD9l9rilXkpuia4Anp4TKHPOrp8/MS/+083g4it4MYED/hc"
href="http://lib.baomitu.com/quill/2.0.0-dev.3/quill.snow.min.css"
rel="stylesheet"
/>
<script
crossorigin="anonymous"
integrity="sha384-MDio1/ps0nK1tabxUqZ+1w2NM9faPltR1mDqXcNleeuiSi0KBXqIsWofIp4r5A0+"
src="http://lib.baomitu.com/quill/2.0.0-dev.3/quill.min.js"
></script>
<script defer src="https://cdn.jsdelivr.net/gh/hunghg255/quill-resize-module/dist/quill-resize-image.min.js"></script>
</head>
<body>
<div id="editor">
<p>Hello World!</p>
<p>Some initial <strong>bold</strong> text</p>
<p><br /></p>
</div>
</body>
<script>
Quill.register("modules/resize", window.QuillResizeImage);
var toolbarOptions = [
"bold",
"italic",
"underline",
"strike",
"image",
"video",
];
var quill = new Quill("#editor", {
theme: "snow",
modules: {
toolbar: toolbarOptions,
resize: {
locale: {
center: "center",
},
},
},
});
</script>
</html>Options
resize: {
locale: {}, // labels: floatLeft, floatRight, center, restore, altTip, inputTip
showToolbar: true, // set to false to hide the floating toolbar and keep only the resize handles
persistAlignment: true, // store left / center / right alignment in the delta (see below)
keepAspectRatio: false, // always keep the aspect ratio (or hold Alt while dragging)
resizeConstraints: { // limits in px
minWidth: 30,
minHeight: 30,
maxWidth: undefined,
maxHeight: undefined,
},
disableMediaTypes: {
disableImages: false,
disableVideos: false,
disableIframes: false,
},
}- Sizes are written as
width/heightattributes (e.g.width="50%") through the Quill API, so they are kept in the delta, in undo history and ingetSemanticHTML(). - Resize handles are available on all four corners and work with touch (pointer events).
- Double clicks on a selected image are forwarded to the image, so your own
dblclickhandlers keep working. - Alignment (left / center / right) is stored in the delta as a
styleattribute of the image / video (e.g.{ insert: { image }, attributes: { style: "float: left; margin: 0px 1em 1em 0px;" } }). To do this the module teaches Quill'simageandvideoformats to keep thefloat,displayandmargininline styles (only those). SetpersistAlignment: falseto opt out.
Cleanup
Call destroy() on the module when the editor is unmounted to remove every listener it registered:
quill.getModule("resize").destroy();React: keep modules stable
If modules (for example a toolbar handlers object) is created inside the component body, React Quill re-creates the editor on every render and the resizer stops working. Memoize it:
const modules = useMemo(() => ({
toolbar: { container: [["image"]], handlers: { image: handleImageUpload } },
resize: { locale: {} },
}), []);All Contributors
Thanks to the following friends for their contributions to project:
