Skip to content

Commit df3c90c

Browse files
authored
Merge pull request #17 from QuentinFringhian/feat/min-resize
2 parents 6b46dee + f2aa7bc commit df3c90c

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/ResizePlugin.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff 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
}
2531
const 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
}

src/main.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

2430
function QuillResizeImage(quill: Quill, options?: QuillResizeImageOptions) {

0 commit comments

Comments
 (0)