Skip to content

Commit

Permalink
fix: develop responsive height
Browse files Browse the repository at this point in the history
  • Loading branch information
bae-sh committed Jul 4, 2024
1 parent 4b7cbf5 commit c87144f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
7 changes: 1 addition & 6 deletions lib/imageResize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const ImageResize = Image.extend({
];

let isResizing = false;
let startX: number, startWidth: number, startHeight: number;
let startX: number, startWidth: number;

$container.addEventListener('click', () => {
//remove remaining dots and position controller
Expand Down Expand Up @@ -215,21 +215,16 @@ export const ImageResize = Image.extend({
isResizing = true;
startX = e.clientX;
startWidth = $container.offsetWidth;
startHeight = $container.offsetHeight;

const onMouseMove = (e: MouseEvent) => {
if (!isResizing) return;
const deltaX = index % 2 === 0 ? -(e.clientX - startX) : e.clientX - startX;

const aspectRatio = startWidth / startHeight;
const newWidth = startWidth + deltaX;
const newHeight = newWidth / aspectRatio;

$container.style.width = newWidth + 'px';
$container.style.height = newHeight + 'px';

$img.style.width = newWidth + 'px';
$img.style.height = newHeight + 'px';
};

const onMouseUp = () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tiptap-extension-resize-image",
"version": "1.1.7",
"version": "1.1.8",
"type": "module",
"description": "A tiptap image resizing extension for React, Vue, Next, and VanillaJS. Additionally, it can align the image position.",
"main": "dist/index.js",
Expand Down

0 comments on commit c87144f

Please sign in to comment.