File tree Expand file tree Collapse file tree 2 files changed +37
-5
lines changed
Expand file tree Collapse file tree 2 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,12 @@ interface ResizePluginOption {
2121 locale ?: Locale ;
2222 [ index : string ] : any ;
2323 keepAspectRatio ?: boolean ;
24+ resizeConstraints ?: {
25+ minWidth ?: number ;
26+ maxWidth ?: number ;
27+ minHeight ?: number ;
28+ maxHeight ?: number ;
29+ } ;
2430}
2531const template = `
2632<div class="handler" title="{0}"></div>
@@ -176,12 +182,32 @@ class ResizePlugin {
176182 height = rate * width ;
177183 }
178184
179- this . resizeTarget . style . setProperty ( "width" , Math . max ( width , 30 ) + "px" ) ;
185+ const minWidth = this . options ?. resizeConstraints ?. minWidth ?? 30 ;
186+ const minHeight = this . options ?. resizeConstraints ?. minHeight ?? 30 ;
187+
188+ if ( width < minWidth ) {
189+ width = minWidth ;
190+ }
191+ if (
192+ this . options ?. resizeConstraints ?. maxWidth !== undefined &&
193+ width > this . options . resizeConstraints . maxWidth
194+ ) {
195+ width = this . options . resizeConstraints . maxWidth ;
196+ }
197+
198+ if ( height < minHeight ) {
199+ height = minHeight ;
200+ }
201+ if (
202+ this . options ?. resizeConstraints ?. maxHeight !== undefined &&
203+ height > this . options . resizeConstraints . maxHeight
204+ ) {
205+ height = this . options . resizeConstraints . maxHeight ;
206+ }
207+ this . resizeTarget . style . setProperty ( "width" , width + "px" ) ;
208+
180209 if ( ! this . options ?. keepAspectRatio ) {
181- this . resizeTarget . style . setProperty (
182- "height" ,
183- Math . max ( height , 30 ) + "px"
184- ) ;
210+ this . resizeTarget . style . setProperty ( "height" , height + "px" ) ;
185211 }
186212 this . positionResizerToTarget ( this . resizeTarget ) ;
187213 }
Original file line number Diff line number Diff line change @@ -19,6 +19,12 @@ interface QuillResizeImageOptions {
1919 disableIframes ?: boolean ;
2020 } ;
2121 keepAspectRatio ?: boolean ;
22+ resizeConstraints ?: {
23+ minWidth ?: number ;
24+ maxWidth ?: number ;
25+ minHeight ?: number ;
26+ maxHeight ?: number ;
27+ } ;
2228}
2329
2430function QuillResizeImage ( quill : Quill , options ?: QuillResizeImageOptions ) {
You can’t perform that action at this time.
0 commit comments